All checks were successful
CI / Get Changed Files (pull_request) Successful in 8s
CI / oxlint (pull_request) Successful in 27s
CI / eslint (pull_request) Successful in 30s
CI / Docker backend validation (pull_request) Successful in 34s
CI / prettier (pull_request) Successful in 38s
CI / Checkstyle Main (pull_request) Successful in 1m1s
CI / Docker frontend validation (pull_request) Successful in 1m2s
CI / test-build (pull_request) Successful in 1m1s
36 lines
940 B
TypeScript
36 lines
940 B
TypeScript
import { inject, Injectable, signal } from '@angular/core';
|
|
import { Router } from '@angular/router';
|
|
import { AuthService } from '@service/auth.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class Oauth2Service {
|
|
private router: Router = inject(Router);
|
|
private authService: AuthService = inject(AuthService);
|
|
private _error = signal<string>('');
|
|
|
|
oauth(provider: string, code: string) {
|
|
const oauth$ =
|
|
provider === 'github' ? this.authService.githubAuth(code) : this.authService.googleAuth(code);
|
|
|
|
oauth$.subscribe({
|
|
next: () => {
|
|
this.router.navigate(['/home']);
|
|
},
|
|
error: (err) => {
|
|
this._error.set(
|
|
err.error?.message || 'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
|
|
);
|
|
|
|
setTimeout(() => {
|
|
this.router.navigate(['/']);
|
|
}, 3000);
|
|
},
|
|
});
|
|
}
|
|
|
|
public get error() {
|
|
return this._error;
|
|
}
|
|
}
|