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

signIn to open flow in a pop-up or new tab #460

Closed
Olyno opened this issue Jul 11, 2021 · 14 comments
Closed

signIn to open flow in a pop-up or new tab #460

Olyno opened this issue Jul 11, 2021 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@Olyno
Copy link

Olyno commented Jul 11, 2021

Bug report

Describe the bug

Signin with a provider redirects the user to the associated provider. Problem: because the user didn't accept to login with his provider's account, we can't get the user, and because the redirection is happening after

await client.auth.signIn({ provider: 'google' });

So the user still "null"

To Reproduce

  1. Create a new project
  2. Adds a provider on a click event
  3. See the problem

Expected behavior

Do not make any redirection. The best is probably to open all redirection in another windows, and when the user signins using the provider, then after that making the redirection if needed.

System information

  • OS: Linux Deepin OS
  • Browser (if applies) Chrome
  • Version of supabase-js: ^1.18.1
  • Version of Node.js: v14.16.1
@Olyno
Copy link
Author

Olyno commented Jul 11, 2021

@jimmiejackson414-zz
Copy link

I think I'm facing the same issue, and am not receiving a redirect of any sort either (though that might be slightly unrelated). I've posted about it in the Discussions as well as on StackOverflow

@megacherry
Copy link

megacherry commented Jul 23, 2021

Are there any news on this issue? :)

@inian inian transferred this issue from supabase/supabase-js Jul 30, 2021
@Olyno
Copy link
Author

Olyno commented Jul 30, 2021

After some discuss with @phamhieu on the discord, here is the real problem: the signIn method with a provider still return an object { user, session, error }, which is wrong because it executes an redirection. Due to that redirection, we're not able to get that data.

You still have the possibility to get the data using client.auth.user() or client.auth.session() BUT during the Supabase's internal loading, both values gonna be null. To fix that, you can use

client.auth.onAuthStateChange((_, session) => {
	setUser(session.user) // Example with React's hooks, just reassign your logged user here
})

@braebo
Copy link

braebo commented Jul 30, 2021

With my use-case, onAuthStateChange doesn't fire.

I believe it's because I use a popup window. I can't let my main window redirect or reload because I need to preserve state (users can work offline, then login to save and continue working).

Consequently, I have a popup window handling Github auth, and inside the popup-window it redirects to /auth/success which displays a success screen before closing itself. It used to also pass the session back to the main window, but that no longer works (it worked a week or two ago iirc).

@awalias
Copy link
Member

awalias commented Jul 30, 2021

moving this to the backend repo

@awalias awalias transferred this issue from supabase/auth-js Jul 30, 2021
@praj18
Copy link

praj18 commented Sep 23, 2021

Has anyone found a solution for this year? I've seen various threads regarding the same issue with no solution in place

@jimmiejackson414-zz
Copy link

@praj18 not really a solution, but an explanation from I believe one of the team members to a StackOverflow post I made back in July.

@kangmingtay
Copy link
Member

kangmingtay commented Sep 14, 2022

Hey everyone, i think this can be partially solved by just opening the OAuth provider in a separate tab rather than in the current window.

Problem: because the user didn't accept to login with his provider's account, we can't get the user, and because the redirection is happening after...So the user still "null"

This seems like expected behaviour. If the user hasn't completed the oauth login flow yet, no user object should be returned.

One other thing to note is that await client.auth.signIn({ provider: 'google' }); doesn't create a user in the auth schema until the redirection is complete.

@hf hf transferred this issue from supabase/auth Sep 29, 2022
@hf hf changed the title Providers return "null" for user signIn to open flow in a pop-up or new tab Sep 29, 2022
@hf
Copy link
Contributor

hf commented Sep 29, 2022

I moved this ticket from the GoTrue repo to here, and changed the title to make it clearer. This should be added to the library whenever we can get to it.

@hf
Copy link
Contributor

hf commented Dec 30, 2022

With #566 this is probably going to become somewhat possible. Keeping the issue open as we need a proper API to launch the flow in a new tab / popup.

@hf
Copy link
Contributor

hf commented Dec 30, 2022

Also #575 may make this even more possible.

@kangmingtay
Copy link
Member

closing this issue because you can set skipBrowserRedirect: true in the signInWithOAuth method which will return a URL that you can open in the pop-up or a new tab

@ecancil
Copy link

ecancil commented Jul 20, 2024

closing this issue because you can set skipBrowserRedirect: true in the signInWithOAuth method which will return a URL that you can open in the pop-up or a new tab

So we're to implement the closing of the popup window and the communication back to the main window. Shouldn't this be very basic supported behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants