cuongdevjs / reactjs-social-login

Group Hook ReactJS components for login social network
https://react-social-login.netlify.app
MIT License
172 stars 76 forks source link

Can't login on Google account the popup doesn't appears #131

Closed rhuber-rbi closed 1 year ago

rhuber-rbi commented 1 year ago

Describe the bug Hi guys I'm getting this error when I use idToken the popup to select the account doesn't appears

Captura de pantalla 2023-09-08 a la(s) 11 51 37

<LoginSocialGoogle client_id={googleServiceWebClientIds} fetch_basic_profile={true} ux_mode={'popup'} typeResponse="idToken" access_type={'offline'} discoveryDocs={'claims_supported'} onResolve={({ data }: IResolveParams) => {

      }}
      onReject={error => {

      }}
      onLoginStart={() =>

      }
    >
     {.....}
    </LoginSocialGoogle>
cuongdevjs commented 1 year ago

remove access_type prop

rhuber-rbi commented 1 year ago

I have already tested but the popup to login doesn't appear consistently, today in the morning I had the problem several times when I clicked on login and any popup appeared also any error on the console or network tab, if you click 3 or 4 times you will not get the google popup anymore

rhuber-rbi commented 1 year ago

also when I make click It fires a request to https://accounts.google.com/gsi/log?client_id.... and the response for that is 200

cuongdevjs commented 1 year ago

try the code below:

<LoginSocialGoogle
                        client_id={
                            ""
                        }
                        onLoginStart={onLoginStart}
                        redirect_uri={REDIRECT_URI}
                        typeResponse="idToken"
                        scope="openid profile email"
                        ux_mode="popup"
                        onResolve={({ provider, data }) => {

                        }}
                        onReject={(err) => {
                            console.log(err);
                        }}
                    >
....
                    </LoginSocialGoogle>
rhuber-rbi commented 1 year ago

nope, same behavior, it works fine 2 or 3 times then it doesn't appears anymore, but the issue is just when we asking for idToken, with accessToken works fine every time

rhuber-rbi commented 1 year ago

When It starts failign I see this message on chrome console issues tab

Captura de pantalla 2023-09-08 a la(s) 15 09 38
cuongdevjs commented 1 year ago

have you tried my demo on site? Does it work?

rhuber-rbi commented 1 year ago

Yes I did it, and for example, if you click on Google login and close the popup and click again the popup doesn't show(applies the same if you make the login 3 or 4 times), I did some more research and I found that this cookie "g_state" is causing that issue if you set this and force a re-render it starts working again

g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT

cuongdevjs commented 1 year ago

you need to call logout function before click to login button again.

rhuber-rbi commented 1 year ago

After the login success, the logout works fine, but the logout doesn't work if I didn't make a login as I'm closing the popup before making the login, I have solved by adding this to the onLoginStart

        window.google.accounts.id.prompt(notification => {
          if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
            // clear g_state cookie if the pop-up has already been closed
            document.cookie = `g_state=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT`;
          }
        });
rhuber-rbi commented 1 year ago

I'm not able to create a branch on your repo, if you want the fix this is the patch, you can test it if you want fix-g_state_google.patch

cuongdevjs commented 1 year ago

if you want to make any changes, please fork this project and make a Pull Request to i can review it. Thank you.