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

Email verification only updates after clearing cache/app data #20

Closed
Ehesp opened this issue Mar 24, 2017 · 14 comments
Closed

Email verification only updates after clearing cache/app data #20

Ehesp opened this issue Mar 24, 2017 · 14 comments
Labels
Service: Authentication Firebase Authentication Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue

Comments

@Ehesp
Copy link
Member

Ehesp commented Mar 24, 2017

When creating an account and sending an email verification, after verifying the email address I can only get the emailVerified prop from onAuthStateChanged to return true after clearing the app data and logging in again.

Only tested on Android at the moment.

@Ehesp Ehesp changed the title Email verification only updates after cache removal Email verification only updates after clearing cache/app data Mar 24, 2017
@Ehesp
Copy link
Member Author

Ehesp commented Mar 24, 2017

Also calling auth().currentUser.reload() has no impact.

@Salakar
Copy link
Member

Salakar commented Mar 24, 2017

Definitely a firebase issue, need to try this on ios also, think it's just android with the problem.

@Ehesp
Copy link
Member Author

Ehesp commented Mar 25, 2017

@xzilja
Copy link
Contributor

xzilja commented Apr 3, 2017

There is a sollution to this

await auth.currentUser.reload()
auth.currentUser.getToken(true)

performing both of these will trigger onAuthStateChanged with updated email without sign out. Only drawback is this won't happen automatically, so you need to provide some sort of screen that asks user to verify their email and has Continue or some other call to action to do this refresh.

What I did is just deep link verification link into email and trigger those functions, that way it works as expected. @Ehesp

@Ehesp
Copy link
Member Author

Ehesp commented Apr 3, 2017

@iljadaderko sounds good will give it a try!

When the user registers I do an Alert with an OK action so I'll give it a go in there (and then on app reloads if it's still false). Could you explain/show a bit more on the deep linking? Not actually tried that yet.

@xzilja
Copy link
Contributor

xzilja commented Apr 4, 2017

@Ehesp I use firebase's Dynamic links for this. Essentially you need to set up email verification to go to your custom page, where you then retrieve verification token and pass it to firebase manually, after this you can redirect to url that is set up in firebase as dynamic link, once app opens this url you can preform that token refresh automatically.

I haven't done this myself but even better approach would be to have email verification link go straight into the app and validate user's token in there.

On react native side, you'll be handling these as per following doc https://facebook.github.io/react-native/docs/linking.html#handling-deep-links

@Salakar
Copy link
Member

Salakar commented Apr 4, 2017

@Ehesp @iljadaderko I could potentially add a native method that runs both reload and getToken(true) for this if needed? Something along the lines of hardRefresh?

@Salakar Salakar added Workflow: Waiting for User Response Blocked waiting for user response. Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue Service: Authentication Firebase Authentication and removed Workflow: Waiting for User Response Blocked waiting for user response. labels Apr 4, 2017
@xzilja
Copy link
Contributor

xzilja commented Apr 6, 2017

@Salakar personally, I'd stick to calling these two methods as is, so you guys can keep your repo as close to firebase as possible.

@Salakar
Copy link
Member

Salakar commented Apr 7, 2017

@Ehesp @iljadaderko in that case can I close this issue? Not much else I can do as its a firebase issue 🙈

@Ehesp Ehesp closed this as completed Apr 7, 2017
@jasan-s
Copy link

jasan-s commented Jun 17, 2017

@iljadaderko @Ehesp just for clarification Ideally I want this to happen:

  1. I send a verification email to user,
  2. User open my custom page and verifies email.
  3. Then there is a dynamic link there that send the user to a screen in my app
  4. When this screen mounts in my app I calls the the two methods:
await auth.currentUser.reload()
auth.currentUser.getToken(true)
  1. Then this would trigger the onAuthStateChanged function.

But If the User decides to instead close the browser(ignoring the dynamic link) and launch my app again. I should keep track that previously verification email was sent, thus take the user to a screen (which shows whenever email is not verified and email has been sent). Upon this Screen mounting I ask User if they already verified their email , is so do some action. At this action run the above 2 methods?

P.S this is only a problem for Android right?

@jasan-s
Copy link

jasan-s commented Jun 20, 2017

I tried the above solution yet I get the error below whenever I just login or signup a user:

TypeError: Cannot read property 'reload' of null at reloadUserAndGetToken$ (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:61924:78) at tryCatch (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:16868:40) at Generator.invoke [as _invoke] (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:17056:22)

After refresh with a user logged in the solution works. Why is it seeing the User as Null in my reload, which I surely trigger after authStateChanged has compleated?
Additionally, at login and signup , onauthStateChnaged does return a user, its just firebase.auth.currentUser outside that is null the first time
@Ehesp what was your flow for user signUp with email verification? where you able to successfully call reload at initial login?

@Vaibhavmarch98
Copy link

Vaibhavmarch98 commented Jul 1, 2018

I faced the same prblm
soln
make a button-> on click-> reload
ask the user to press the button after the user has been verfied
in reload do not run .reload() its not working
but manually sign in and sign out

@tkow
Copy link

tkow commented May 19, 2019

Same to me. And getToken method may be currently removed.
Is there an alternative way?

added

I can use getIdtoken force and idTokenListener or onUserChanged instead.

@mikehardy
Copy link
Collaborator

@tkow you have added a comment to a closed issue almost a year old, open a fresh issue with full information. I suspect this may be a need to update all the dependencies, because I have integrated firebase recently with current dependencies and this does not happen to me - I was able to use the sample code in the auth docs on rnfirebase.io and everything is fine.

@invertase invertase locked as resolved and limited conversation to collaborators May 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Service: Authentication Firebase Authentication Type: Firebase Issue or PR that addresses external Firebase behaviour issues or changes, e.g. a Firebase SDK issue
Projects
None yet
Development

No branches or pull requests

7 participants