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 {
|
try {
|
||||||
console.log('Logging out');
|
console.log('Logging out');
|
||||||
this.user = null;
|
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('access_token');
|
||||||
|
localStorage.removeItem('id_token');
|
||||||
|
localStorage.removeItem('refresh_token');
|
||||||
sessionStorage.removeItem('access_token');
|
sessionStorage.removeItem('access_token');
|
||||||
|
sessionStorage.removeItem('id_token');
|
||||||
|
sessionStorage.removeItem('refresh_token');
|
||||||
|
|
||||||
|
// Navigate to landing page
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Exception in logout:', err);
|
console.error('Exception in logout:', err);
|
||||||
// Force clear tokens
|
// Force clear tokens locally
|
||||||
this.oauthService.revokeTokenAndLogout().catch(() => {
|
localStorage.clear(); // Clear all local storage as a last resort
|
||||||
// Just navigate to home page as fallback
|
sessionStorage.clear();
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue