Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallet] Fix firebase initialization error on iOS after reinstalling the app #1423

Merged
merged 3 commits into from
Oct 23, 2019

Conversation

jeanregisser
Copy link
Contributor

@jeanregisser jeanregisser commented Oct 22, 2019

Description

Reset iOS keychain on first app run to fix firebase initialization error after reinstalling the app.

Here's what happened:

  • on the very first run, redeeming an invite code worked successfully and
    firebase could initialize correctly
  • after the app is deleted and reinstalled, redeeming an invite code led to a firebase initialization error (permission error in the db)
  • the reason for this is the firebase auth user for both session was the same since Firebase stores the auth credentials in the keychain which is not cleared when the app is uninstalled
  • this had the consequence of the app referencing the old address in the /users/$uid path in the db, and hence causing subsequent permission errors as the rules for changing /registrations/$address or reading /pendingRequests/$address could not be satisfied (you can only read/write them if the address matches the address set in /users/$uid)

The fix here makes sure the keychain is cleared after a reinstall of the app and before we configure firebase (that's when it reads the persisted auth info from the keychain).

Note that react-native-secure-key-store is already ensuring the keychain is cleared on app reinstall but it's run too late (after firebase configure has been called).

Tested

  1. Reset the simulator completely
  2. redeem an invite code, -> firebase initializes successfully
  3. delete the app and reinstall it,
  4. redeem an invite code, -> firebase initializes successfully (firebase auth user id is a new one)

Other changes

N/A

Related issues

Backwards compatibility

Yes

…ror after reinstalling the app

Here's what happened:
- on the very first run, redeeming an invite code worked successfully and
firebase could initialize correctly
- after the app is deleted and reinstalled, redeeming an invite code led
to a firebase initialization error (permission error in the db)
- the reason for this is the firebase auth user for both session was
the same since Firebase stores the auth credentials in the keychain
which is not cleared when the app is uninstalled
- this had the consequence of the app referencing the old address in the
/users/$uid path in the db, and hence causing subsequent permission
errors as the rules for changing /registrations/$address or reading
/pendingRequests/$address could not be satisfied (you can only
read/write them) if the address matches the address set in /users/$uid

The fix here makes sure the keychain is cleared after a reinstall of the
app and before we configure firebase (that's when it reads the persisted
auth info from the keychain).

Note that react-native-secure-key-store is already ensuring the keychain
is cleared on app reinstall but it's run too late (after firebase
configure has been called).
…ress

This is to ensure that there's not a logic error that breaks our current
assumptions in the future
} else if (userData.address !== undefined && userData.address !== address) {
// This shouldn't happen! If this is thrown it means the firebase user is reused
// with different addresses (which we don't want) or the db was incorrectly changed remotely!
throw new Error("User address in the db doesn't match persisted address")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to confirm that it was intentional to throw here instead of returning undefined? This callback is what will run on the db to modify the data. I don't think the error will propagate to the app, but I could be wrong. I'm uncertain what happens if we throw here.

Copy link
Contributor Author

@jeanregisser jeanregisser Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question!
It triggers a red screen in dev, and it's not captured by the saga promise flow.
It's logged by Sentry and crashes the app. Which is what I intended as I see it like a logic error which shouldn't happen.

@codecov
Copy link

codecov bot commented Oct 22, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@98b068c). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1423   +/-   ##
=========================================
  Coverage          ?   67.25%           
=========================================
  Files             ?      267           
  Lines             ?     7884           
  Branches          ?      531           
=========================================
  Hits              ?     5302           
  Misses            ?     2476           
  Partials          ?      106
Flag Coverage Δ
#mobile 67.25% <0%> (?)
Impacted Files Coverage Δ
packages/mobile/src/firebase/firebase.ts 20.28% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98b068c...4098b1f. Read the comment docs.

@jeanregisser jeanregisser assigned jmrossy and unassigned jeanregisser Oct 22, 2019
@jmrossy jmrossy assigned jeanregisser and unassigned jmrossy Oct 23, 2019
@jeanregisser jeanregisser merged commit 82a97ef into master Oct 23, 2019
@jeanregisser jeanregisser deleted the jeanregisser/fix-ios-firebase-init-error branch October 23, 2019 11:42
aaronmgdr added a commit that referenced this pull request Oct 24, 2019
* master:
  [Wallet] Wallet can switch between hosted and local node (#1419)
  [Wallet] Prevent error from Avatar when name is missing (#1454)
  [Wallet] Show splash screen until JS is ready on iOS (#1453)
  Use new segment api keys used by both iOS and Android (#1452)
  [Wallet] Don't log all props, which includes i18n (#1445)
  [Helm] Updated the helm package to deploy the upgraded blockscout version (#1129)
  Tiny copy change (#1429)
  [contractkit] SortedOraclesWrapper + tests (#1405)
  [wallet] Refactor leftover thunk to sagas (#1388)
  [Wallet] Fix repeated QR code scanning and related navigation issues (#1439)
  [Wallet] Show the currency values with correct rounding. (#1435)
  [Wallet] Fix firebase initialization error on iOS after reinstalling the app (#1423)
  [Wallet] Use exit on iOS since we can't restart like Android (#1424)
  [Wallet] Update local currency styles and layout (#1325)
  Reset pincode cache if unlock fails (#1430)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firebase initialization error while redeeming an invite code on iOS
2 participants