refactor: rename keycloakId to authentikId in codebase
Some checks failed
CI / Get Changed Files (pull_request) Successful in 6s
CI / prettier (pull_request) Failing after 46s
CI / Checkstyle Main (pull_request) Successful in 49s
CI / eslint (pull_request) Failing after 1m2s
CI / test-build (pull_request) Failing after 1m9s

This commit is contained in:
Jan K9f 2025-04-02 15:49:58 +02:00
commit 8317349507
Signed by: jank
GPG key ID: B9F475106B20F144
12 changed files with 270 additions and 48 deletions

View file

@ -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);
}
}
}