abacritt / angularx-social-login

Social login and authentication module for Angular 17
630 stars 387 forks source link

Autologin not working on browser refresh #632

Closed Souvik-Root closed 1 year ago

Souvik-Root commented 1 year ago

Autologin seems to be not working for me on browser refresh. I have set the property 'autoLogin: true' as well.

I am subscribed to the authstate, but after page refresh, socialUser is null.

Here is the code -

` this.authService.authState.subscribe((user) => { this.user = user; this.loggedIn = (user != null);

  if (this.loggedIn) {
    this._snackBar.open('Welcome ' + user.firstName + ' ' + user.lastName + '!', 'Dismiss', {
      duration: 3000,
    });
  }
  else {
    this._snackBar.open('Logged out!', 'Dismiss', {
      duration: 3000,
    });

} `

theophane-girard commented 1 year ago

Same problem here

cody-01 commented 1 year ago

I had to enable oneTap to get it to work on refresh

const googleOptions: GoogleInitOptions = { oneTapEnabled: true };

Souvik-Root commented 1 year ago

@cody-01 This doesn't seem to work for me. I have added this to the app.module.ts

providers: [
        ...,
        {
            provide: 'SocialAuthServiceConfig',
            useValue: {
                autoLogin: true,
                providers: [
                    {
                        id: GoogleLoginProvider.PROVIDER_ID,
                        provider: new GoogleLoginProvider('Google-OAuth-Client-Id', { oneTapEnabled: true }),
                    },
                ],
                onError: (err) => {
                    console.error(err);
                }
            } as SocialAuthServiceConfig,
        }
    ],
cody-01 commented 1 year ago

@Souvik-Root you may need to inject the SocialAuthService into your component to get the OneTap dialog box to appear, which will auto-sign in the user if they've signed in before. Like in app-component.ts if you want to detect and login site-wide.

FWIW, I was running into issues with making gapi calendar API calls after authenticating with this plugin and using the access_token. So I decided to try and authenticate users directly with Google GIS (without this plugin), and then use instantiate a TokenClient and it was actually easier. I removed the plugin

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.