feat(auth): improve logout functionality and token management
Some checks failed
Some checks failed
This commit is contained in:
parent
47f4a4d558
commit
2e76446328
1 changed files with 18 additions and 7 deletions
|
@ -206,18 +206,29 @@ export class AuthService {
|
|||
try {
|
||||
console.log('Logging out');
|
||||
this.user = null;
|
||||
this.oauthService.logOut();
|
||||
// Clear any lingering token in storage
|
||||
|
||||
// Prevent redirect to Authentik by doing a local logout only
|
||||
// Instead of using oauthService.logOut() which redirects to the provider
|
||||
|
||||
// Clear tokens from storage
|
||||
this.oauthService.logOut(false); // logOut(false) prevents redirect
|
||||
|
||||
// Clear any lingering tokens manually
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('id_token');
|
||||
localStorage.removeItem('refresh_token');
|
||||
sessionStorage.removeItem('access_token');
|
||||
sessionStorage.removeItem('id_token');
|
||||
sessionStorage.removeItem('refresh_token');
|
||||
|
||||
// Navigate to landing page
|
||||
this.router.navigate(['/']);
|
||||
} catch (err) {
|
||||
console.error('Exception in logout:', err);
|
||||
// Force clear tokens
|
||||
this.oauthService.revokeTokenAndLogout().catch(() => {
|
||||
// Just navigate to home page as fallback
|
||||
// Force clear tokens locally
|
||||
localStorage.clear(); // Clear all local storage as a last resort
|
||||
sessionStorage.clear();
|
||||
this.router.navigate(['/']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue