How Do I Prevent the Google Login Prompt from Showing Despite Being Logged in in my Angular...

Discussão em 'Angular' iniciado por Vihung, Maio 29, 2025.

  1. Vihung

    Vihung Guest

    I have an Angular app that uses routing to go between, essentially, two "pages" - a data recording screen and an analysis report screen. I am using the AngularX Social Login (https://github.com/abacritt/angularx-social-login] module with Google as my provider in my app.

    Logging on with Google is fine. However, once logged in, when I switch between pages, the google prompt comes up each time.

    [​IMG]

    For example, if I am logged in using Google and I record some data, when I switch to the analysis screen, a google popup appears. It knows I am logged in, and knows who I am logged in as, and it offers a confirmation with a "Continue as user" button.

    [​IMG]

    In my application, my index.html is essentially

    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>

    <body>
    <app-root></app-root>
    </body>
    </html>


    My routing is

    const routes: Routes = [
    { path: 'record', component: RecordComponent },
    { path: 'analyse', component: AnalyseComponent },
    { path: 'profile', component: ProfileComponent },
    { path: '', redirectTo: '/record', pathMatch: 'full' }, // redirect to `record`
    ];


    My AppModule's config is

    providers: [
    {
    provide: 'SocialAuthServiceConfig',
    useValue: {
    autoLogin: false,
    providers: [
    {
    id: GoogleLoginProvider.PROVIDER_ID,
    provider: new GoogleLoginProvider(
    'foo.apps.googleusercontent.com'
    )
    }
    ],
    onError: (err) => {
    console.error(err);
    }
    } as SocialAuthServiceConfig,
    }
    ],


    My AppComponent is

    export class AppComponent {
    user: SocialUser = null;

    constructor(
    private _authService: SocialAuthService
    ) {
    this._authService.authState.subscribe((user) => {
    this.user = user;
    });
    }
    }


    and its HTML is

    <div class="container">

    <div *ngIf="!user">
    <h2>Login</h2>
    <asl-google-signin-button type='standard' size='medium'></asl-google-signin-button>
    </div>

    <div *ngIf="user">
    <router-outlet></router-outlet>
    </div>
    </div>


    I am using Angular 16 (16.2.2) and angularx-social-login version 2.1.0.

    Continue reading...

Compartilhe esta Página