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

output of oAuth signin in v2 #417

Closed
bhvngt opened this issue Aug 28, 2022 · 10 comments · Fixed by #575
Closed

output of oAuth signin in v2 #417

bhvngt opened this issue Aug 28, 2022 · 10 comments · Fixed by #575
Labels
documentation Improvements or additions to documentation released

Comments

@bhvngt
Copy link

bhvngt commented Aug 28, 2022

Improve documentation

Link

https://supabase.com/docs/reference/javascript/next/auth-signinwithoauth#examples

Describe the problem

oAuth signin example in the link above suggest that signInWithOAuth returns regular data object that contains session.For ref: it documents following line in the code snippet.

const oAuthToken = data.session.provider_token // use to access provider API

In v1 it used to return User and Session object.

However while trying to migrate I discovered that OAuthResponse return provider name and url returned by the provider. I am not sure if this is intentional or is it work in progress? Because, it seems inconsistent with other auth methods and v1 and it is also different from what the v2 documentation is suggesting.

###Is the documentation missing? Or is it confusing? Why is it confusing?

It is confusing

Describe the improvement

Ideally, I would prefer if the signInWithOAuth returns data object of type AuthResponse to keep it consistent. If not then the example should describe how one can derive Session and User object from OAuthResponse object.

@bhvngt bhvngt added the documentation Improvements or additions to documentation label Aug 28, 2022
@saschwarz
Copy link

I'm trying to migrate to v2 and I also can't figure out how to get the authenticated user when using signInWithOAuth

@ankushg
Copy link

ankushg commented Dec 25, 2022

Hi, also curious about this -- are there any examples on how to get a Session/User object after getting an OAuthResponse?

Are we supposed to just call supabase.auth.getSession() after we get a non-error OAuthResponse?

@hf
Copy link
Contributor

hf commented Dec 30, 2022

If I'm not mistaken signInWithOAuth will basically never return a data object in a browser. (At least not in this form.)

This is because the way OAuth sign-in works is the current window location will be set to the authorization URL for the OAuth provider. If calling from a non-browser environment such as React Native, Flutter or other such environments, since there's no window.location there you will receive the URL to open in a browser.

I've added an option that will let you access the data object in #575.

@hf hf closed this as completed Dec 30, 2022
@saschwarz
Copy link

@hf I looked at #575 but there don't seem to be any examples/documentation on how to use that new option to get the session/user?

@hf
Copy link
Contributor

hf commented Dec 30, 2022

Unfortunately the OAuth flow is very asynchronous and I'm not super keen on adding hacks such as:

new Promise((accept, reject) => {
  supabase.auth.onAuthStateChange((event, session) => {
    if (event === 'SIGNED_IN') { accept(session) }
  })
})

You kinda have to do this via the onAuthStateChange callback for the time being. I'm happy to discuss other ideas if you have any.

@saschwarz
Copy link

saschwarz commented Dec 30, 2022

@hf I don't think anyone is asking for the code to change. When you closed this ticket your comment implied the pull request included the documentation requested in this case. But, when I looked at the pull request it adds a new flag and I didn't see the connection between the flag and the documentation requested by this issue.

In v1 it was clear how you got the user/session. I just re-checked and the current documentation/auth video doesn't have any links or examples (that I could find) about what new devs need to do once they call signInWithOAuth.

I'm sure it is obvious to you what needs to be done. But, I'd love to see a full worked out example.

So I think this request for documentation is still valid.

@hf
Copy link
Contributor

hf commented Dec 31, 2022

So I think this request for documentation is still valid.

Yes you're right. Reopening.

@hf hf reopened this Dec 31, 2022
@hf hf closed this as completed in #575 Jan 23, 2023
hf added a commit that referenced this issue Jan 23, 2023
Allows for custom handling of the redirect URL when in browser
environments.

Fixes: #417
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 2.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@saschwarz
Copy link

saschwarz commented Jan 23, 2023

@hf I didn't see any documentation updates as part of #572 ? Is there documentation of using OAuth in v2 and getting the User and Session?

@Jpaulsisson
Copy link

Can someone please just explain to me how to get the user and session data from the signInWithOAuth method so I can move on with my life?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants