feat(auth): implement Google OAuth2 authentication flow #211

Merged
csimonis merged 6 commits from feat/google-oauth into main 2025-05-21 10:00:57 +00:00
3 changed files with 9 additions and 8 deletions
Showing only changes of commit f3ab9ffcd6 - Show all commits

View file

@ -52,7 +52,7 @@ export const routes: Routes = [
),
data: { provider: 'google' },
},
]
],
},
{
path: 'game/blackjack',

View file

@ -1,7 +1,6 @@
import { Component, computed, inject, OnInit, Signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '@service/auth.service';
import { Oauth2Service } from './oauth2.service';
@Component({
@ -35,7 +34,9 @@ export class OAuth2CallbackComponent implements OnInit {
if (code) {
this.oauthService.oauth(provider, code);
} else {
this.oauthService.error.set('Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.');
this.oauthService.error.set(
'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
);
setTimeout(() => {
this.router.navigate(['/']);

View file

@ -2,7 +2,6 @@ import { inject, Injectable, signal } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@service/auth.service';
@Injectable({
providedIn: 'root',
})
@ -12,16 +11,17 @@ export class Oauth2Service {
private _error = signal<string>('');
oauth(provider: string, code: string) {
const oauth$ = provider === 'github'
? this.authService.githubAuth(code)
: this.authService.googleAuth(code);
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.');
this._error.set(
err.error?.message || 'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
);
setTimeout(() => {
this.router.navigate(['/']);