feat(auth): restructure oauth2 callback handling and service
Some checks failed
CI / Get Changed Files (pull_request) Successful in 8s
CI / Docker backend validation (pull_request) Successful in 26s
CI / eslint (pull_request) Failing after 32s
CI / oxlint (pull_request) Failing after 36s
CI / prettier (pull_request) Failing after 39s
CI / Checkstyle Main (pull_request) Successful in 55s
CI / Docker frontend validation (pull_request) Successful in 1m4s
CI / test-build (pull_request) Successful in 1m1s

This commit is contained in:
Constantin Simonis 2025-05-21 11:50:41 +02:00
commit eb1717bca1
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
3 changed files with 65 additions and 55 deletions

View file

@ -0,0 +1,36 @@
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;
}
}