Skip to content

Firebase Auth w/Provider: Calling getRedirectResult() is unecessary, documentation is flawed #1682

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

Closed
junkomatic opened this issue Apr 10, 2019 · 7 comments

Comments

@junkomatic
Copy link

In all of the documentation/examples I can find, getRedirectResult() is called immediately after signInWithRedirect() is called. Even using .then, getRedirectResult returns immediately with a null user in the result, before the redirect even happens. This is not useful. Is there a way of detecting the actual redirect before calling 'getRedirectResult()'?

With the inclusion of the 'onAuthStateChanged' observer, which apparently waits until getRedirectResult actually resolves with a non-null user object, it seems like the inclusion of calling getRedirectResult only causes confusion.

Is anyone actually using a call to 'getRedirectResult()' in their auth flow/implementations? There are currently several unsolved stack overflow questions about it returning null, with suggestions mainly pointing to: "forget it, and just use onAuthStateChanged".

Screenshot from official documentation telling people to do it this way:
Screenshot from 2019-04-09 21-53-36

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@bojeil-google
Copy link
Contributor

These are just snippets. They are not meant to be copied and pasted as is.

Typically signInWithRedirect is called upon some action (a button click on a sign-in page).

In most cases, getRedirectResult is not needed. onAuthStateChanged is sufficient for successful flows, but a developer may want to get the results (OAuth credentials, additional user info, etc), or recover from certain errors (email already exists, linking is required, etc) or show error message to the user (account disabled, etc). They can call this API to get that information.

How the above is wired varies on your requirements.

@orofbrown
Copy link

@bojeil-google I think your answer makes sense, and I can appreciate that. But I also strongly agree with what @junkomatic is saying because the documentation example is very misleading. It implies that you need to use all of these pieces to get logged in, and if you're new to this process, it's very difficult to put the pieces together correctly. It would be helpful if the example was clearer or there was another, simpler version.

@shanehsu
Copy link

I'm not sure where you got that screenshot, but the documentation on Firebase now shows,

To sign in by redirecting to the sign-in page, call signInWithRedirect:

firebase.auth().signInWithRedirect(provider);

Then, you can also retrieve the Facebook provider's OAuth token by calling getRedirectResult when your page loads

firebase.auth().getRedirectResult().then(function(result) {
  // other code

This looks fair enough to me.

@rommelpe
Copy link

For an additional context, you may also check out our quickstart guide in facebook redirect for a sample use case of onAuthStateChanged & getRedirectResult.

@google-oss-bot
Copy link
Contributor

Hey @junkomatic. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@junkomatic if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants