This repository has been archived on 2025-06-18. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
casino/frontend/src/app/feature/login-success/login-success.component.ts
Jan K9f 02453449cd
All checks were successful
CI / Get Changed Files (pull_request) Successful in 6s
CI / eslint (pull_request) Successful in 25s
CI / test-build (pull_request) Successful in 31s
CI / prettier (pull_request) Successful in 56s
CI / Checkstyle Main (pull_request) Successful in 2m12s
refactor(user): clean up comments and rename variables
2025-04-03 11:51:55 +02:00

43 lines
1.3 KiB
TypeScript

import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../service/auth.service';
import { OAuthService } from 'angular-oauth2-oidc';
@Component({
selector: 'app-login-success',
standalone: true,
imports: [],
templateUrl: './login-success.component.html',
styleUrl: './login-success.component.css',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export default class LoginSuccessComponent implements OnInit {
private authService: AuthService = inject(AuthService);
private oauthService: OAuthService = inject(OAuthService);
private router: Router = inject(Router);
async ngOnInit() {
try {
if (this.oauthService.hasValidAccessToken()) {
this.router.navigate(['/home']);
} else {
setTimeout(() => {
if (this.oauthService.hasValidAccessToken() || this.authService.getUser()) {
this.router.navigate(['/home']);
} else {
this.router.navigate(['/']);
}
}, 3000);
}
} catch (err) {
console.error('Error during login callback:', err);
setTimeout(() => {
if (this.authService.isLoggedIn()) {
this.router.navigate(['/home']);
} else {
this.router.navigate(['/']);
}
}, 3000);
}
}
}