refactor: rename keycloakId to authentikId in codebase
Some checks failed
Some checks failed
This commit is contained in:
parent
7eebd12699
commit
8317349507
12 changed files with 270 additions and 48 deletions
|
@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/cor
|
|||
import { Router } from '@angular/router';
|
||||
import { AuthService } from '../../service/auth.service';
|
||||
import { User } from '../../model/User';
|
||||
import { OAuthService } from 'angular-oauth2-oidc';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login-success',
|
||||
|
@ -13,7 +14,48 @@ import { User } from '../../model/User';
|
|||
})
|
||||
export default class LoginSuccessComponent implements OnInit {
|
||||
private authService: AuthService = inject(AuthService);
|
||||
private oauthService: OAuthService = inject(OAuthService);
|
||||
private router: Router = inject(Router);
|
||||
|
||||
async ngOnInit() {
|
||||
console.log(this.authService.getUser())
|
||||
console.log('Login success component initialized');
|
||||
|
||||
try {
|
||||
// Handle code flow without throwing errors
|
||||
const success = await this.oauthService.loadDiscoveryDocumentAndTryLogin();
|
||||
console.log('Manual login attempt result:', success);
|
||||
|
||||
// If we have a valid access token, the user should be loaded in AuthService
|
||||
const user = this.authService.getUser();
|
||||
console.log('Login success user:', user);
|
||||
|
||||
// Check if we're authenticated
|
||||
if (this.oauthService.hasValidAccessToken()) {
|
||||
console.log('Valid access token found');
|
||||
this.router.navigate(['/home']);
|
||||
} else {
|
||||
console.log('No valid access token, waiting for auth service to complete');
|
||||
// Wait a bit and check if we've been authenticated in the meantime
|
||||
setTimeout(() => {
|
||||
if (this.oauthService.hasValidAccessToken() || this.authService.getUser()) {
|
||||
console.log('Now authenticated, navigating to home');
|
||||
this.router.navigate(['/home']);
|
||||
} else {
|
||||
console.log('Still not authenticated, redirecting to login page');
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error during login callback:', err);
|
||||
// Wait a bit in case token processing is happening elsewhere
|
||||
setTimeout(() => {
|
||||
if (this.authService.isLoggedIn()) {
|
||||
this.router.navigate(['/home']);
|
||||
} else {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue