Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socialAuthService.signout doesn't clear the user and I can't stop autologin. #764

Open
AlejandroFlorin opened this issue Apr 26, 2024 · 4 comments

Comments

@AlejandroFlorin
Copy link

AlejandroFlorin commented Apr 26, 2024

I'm on 2.0.0

When I call socialAuthService.signOut(). The service's user property isn't cleared. Is that expected behavior?

The reason I ask is because I have a login component that subscribes to authState which works great. I also have a logout component that routes back to the login component.

The issue I'm running into is that when the login component is re initialized when routed to from logout, the authservice still thinks the user is logged in and is firing my code to load the post login UI for the user (when they should remain logged out). The autologin flag is set to false BTW.

I have registered the providers in one place (app.module.ts) and subscrbing to the service solely in the login component.

My workaround has been to detect that the login page was reached via a logout reroute and doing a location.reload to clear the service (which is hacky as hell)>. I tried unsubscribing from the autservice but that didn't work.

Thanks

@PRE-ShashankPatil
Copy link

PRE-ShashankPatil commented Jun 19, 2024

Hi, guys any updates ?

Specially in case of Microsoft, i wanted to my application should logout instead of Microsoft account logout popup.

@dimeloper
Copy link

Facing the exact same problem. Are there any known workarounds?

@yurisimoes
Copy link

Facing the same problem

@phl3x0r
Copy link

phl3x0r commented Aug 8, 2024

I had a similar issue so putting my solution here in case it helps anyone.

What I had was this (logout.ts):

ngOnInit(): void {
    this._socialAuthService.authState
            .pipe(
                filter((authState) => !!authState),
                switchMap(() => this._socialAuthService.signOut()),
                takeUntil(this.destroy$)
            )
            .subscribe();
}

but for some reason, it would sometimes not pass the filter, so changed it to automatically sign out after authenticating with the backend like this on the login page (login.ts):

ngOnInit(): void {
        this._socialAuthService.authState
            .pipe(
                filter((authState) => !!authState?.idToken),
                switchMap((authState) =>
                    this._authService.signInWithGoogle(
                        authState.idToken,
                        authState.name
                    )
                ),
                finalize(
                    async () =>
                        await this._socialAuthService
                            .signOut()
                            .catch((error) =>
                                console.error(
                                    'There was a problem signing out of social login: ',
                                    error
                                )
                            )
                ),
                takeUntil(this.destroy$)
            )
            .subscribe(this.handleSignInResponse);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants