Skip to content

Nothing happen after login with Google #823

Closed

Description

@NicolasDeGouveia

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

After setting up my login with credentials (that work perfectly good) i tried to setup the google provider. I followed the documentation but when i click to login, i'm redirected to the google login page, i choose the user that i want, and then i'm redirect to my app but not connected. I see the new user in the database with the status "never" in the row "Last Sign In". When i try again that row update with the current date but in my app i'm not logged in.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go tologin
  2. Click on google button
  3. redirected to my website but not connected

Expected behavior

I want to be connected after the google redirection.

Screenshots

this is my login function : https://gyazo.com/bd500927a2a5331ec5a54ff34ab87204

this the URL i got when i'm redirect to my website : https://gyazo.com/73724c00ad7a62ce9be91e7b90a81385

System information

  • OS: widnows
  • Browser (if applies) chrome
  • Version of supabase-js: 2.31.0
  • Version of Node.js: v16.14.2

Additional context

Add any other context about the problem here.

Activity

  1. added
    bug
    on Jul 28, 2023
  2. j4crev commented on Aug 2, 2023

    @j4crev
    Contributor

    Are you using hosted supabase or a local stand-alone?

  3. NicolasDeGouveia commented on Aug 8, 2023

    @NicolasDeGouveia
    Author

    I'm using a local stand-alone

  4. kangmingtay commented on Aug 21, 2023

    @kangmingtay
    Member

    @NicolasDeGouveia can you please include the code you used to initialise the supabase client?

  5. NicolasDeGouveia commented on Aug 21, 2023

    @NicolasDeGouveia
    Author

    I initialize the supabase client with : const supabase = createClientComponentClient();

  6. kangmingtay commented on Aug 21, 2023

    @kangmingtay
    Member

    @NicolasDeGouveia are you calling the handleSignInClick function from the client-side or server-side? the supabase client you created with createClientComponentClient() returns a supabase client that uses PKCE for auth. This means that after the oauth flow is completed with google, supabase auth returns a code in the query param which will be exchange for a pair of access and refresh tokens.

    If you open up your browser network inspector when being redirected to http://localhost:3000?code...., you should be able to see requests made to /token?grant_type=pkce and check if they are failing. This is the endpoint that handles the code exchange i mentioned earlier. If no requests are made to that endpoint, can you reach out to us via support (https://app.supabase.com/support/new) and we can investigate further.

  7. NicolasDeGouveia commented on Aug 24, 2023

    @NicolasDeGouveia
    Author

    @kangmingtay I'm using it in the client-side. I don't know why but now it's seems to work, but now when i'm logged with google i'm well redirected to my homepage but i must press F5 to be able to see the user connected, even if i have a router.refresh() in my function :

        const handleSignGoogle = async () => {
            await supabase.auth.signInWithOAuth({
                provider: 'google',
                options: {
                    queryParams: {
                        access_type: 'offline',
                        prompt: 'consent',
                    },
                },
            });
            router.refresh();
        };
    

    Any ideas of why ?

  8. kangmingtay commented on Aug 24, 2023

    @kangmingtay
    Member

    @NicolasDeGouveia not too sure what router.refresh() here does but calling it right after signInWithOAuth() won't help because signInWithOAuth() only redirects you to the oauth provider (google) to kickstart the oauth flow. After authenticating with google, you are actually redirected to an endpoint on Supabase Auth first before redirecting again back to the client.

    You can try moving router.refresh() to your homepage and see if that helps. Since this issue is resolved, i'm gonna mark it as closed for now.

  9. umershabir commented on Nov 8, 2024

    @umershabir

    I am literally getting frustrating what is going wrong, const signInWithGoogle = async () => {
    try {
    const { data, error } = await supabase.auth.signInWithOAuth({
    provider: "google",
    options: {
    redirectTo: ${window.location.origin}/menu/,
    scopes: "email profile", // Add required scopes
    },
    });

      if (error) throw error;
      console.log("Sign in initiated:", data); // Debug log
    } catch (error) {
      console.error("Sign in error:", error);
      throw error;
    }
    

    };

    what I am doing wrong here, it follow the oauth flow, then nothin happens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions