react-oauth icon indicating copy to clipboard operation
react-oauth copied to clipboard

onSuccess is not being called when I try to login with useGoogleLogin

Open Lenur29 opened this issue 1 year ago • 3 comments

Here is my demo component. When I try to login with google, it redirects to http://localhost:3000/sign-in with all google info in the url, but does not call onSuccess or onError functions. Please hekp to resolve the issue

import { useGoogleLogin } from '@react-oauth/google';

export const SignInPage = () => {
  const login = useGoogleLogin({
    onSuccess: tokenResponse => console.log(tokenResponse),
    onError: () => {
      console.log('Login Failed');
    },
    flow: 'auth-code',
    ux_mode: 'redirect',
    redirect_uri: 'http://localhost:3000/sign-in',
  });

  return (
    <button type="button" onClick={() => login()}>
      Google login
    </button>
  );
};

Lenur29 avatar Apr 22 '24 16:04 Lenur29

same issue for me

DagonWat avatar May 01 '24 08:05 DagonWat

@Lenur29 did you find a solution?

eakenbor avatar Aug 19 '24 17:08 eakenbor

My issue with this had to do with the COOP header being set to same-origin: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy. There is another callback called onNonOAuthError that you can hook into and console log to find out if it's dropping the popup prematurely.

tylergriffithsclozd avatar Dec 16 '24 21:12 tylergriffithsclozd