diff --git a/frontend/src/app/feature/auth/login/login.component.ts b/frontend/src/app/feature/auth/login/login.component.ts
index 2b78f29..09c1cdf 100644
--- a/frontend/src/app/feature/auth/login/login.component.ts
+++ b/frontend/src/app/feature/auth/login/login.component.ts
@@ -71,6 +71,11 @@ export class LoginComponent {
window.location.href = `${environment.apiUrl}/oauth2/github/authorize`;
}
+ loginWithGoogle(): void {
+ this.isLoading.set(true);
+ window.location.href = `${environment.apiUrl}/oauth2/google/authorize`;
+ }
+
switchToForgotPassword() {
this.forgotPassword.emit();
}
diff --git a/frontend/src/app/feature/auth/oauth2/oauth2-callback.component.ts b/frontend/src/app/feature/auth/oauth2/oauth2-callback.component.ts
index f905f75..d07320a 100644
--- a/frontend/src/app/feature/auth/oauth2/oauth2-callback.component.ts
+++ b/frontend/src/app/feature/auth/oauth2/oauth2-callback.component.ts
@@ -32,25 +32,46 @@ export class OAuth2CallbackComponent implements OnInit {
// Check for code in URL params
this.route.queryParams.subscribe((params) => {
const code = params['code'];
+ const provider = this.route.snapshot.data['provider'] || 'github';
if (code) {
- // Exchange GitHub code for a JWT token
- this.authService.githubAuth(code).subscribe({
- next: () => {
- // Redirect to home after successful authentication
- this.router.navigate(['/home']);
- },
- error: (err) => {
- console.error('GitHub authentication error:', err);
- this.error = err.error?.message || 'Authentication failed. Please try again.';
- console.log('Error details:', err);
+ if (provider === 'google') {
+ // Exchange Google code for a JWT token
+ this.authService.googleAuth(code).subscribe({
+ next: () => {
+ // Redirect to home after successful authentication
+ this.router.navigate(['/home']);
+ },
+ error: (err) => {
+ console.error('Google authentication error:', err);
+ this.error = err.error?.message || 'Authentication failed. Please try again.';
+ console.log('Error details:', err);
- // Redirect back to landing page after showing error
- setTimeout(() => {
- this.router.navigate(['/']);
- }, 3000);
- },
- });
+ // Redirect back to landing page after showing error
+ setTimeout(() => {
+ this.router.navigate(['/']);
+ }, 3000);
+ },
+ });
+ } else {
+ // Exchange GitHub code for a JWT token
+ this.authService.githubAuth(code).subscribe({
+ next: () => {
+ // Redirect to home after successful authentication
+ this.router.navigate(['/home']);
+ },
+ error: (err) => {
+ console.error('GitHub authentication error:', err);
+ this.error = err.error?.message || 'Authentication failed. Please try again.';
+ console.log('Error details:', err);
+
+ // Redirect back to landing page after showing error
+ setTimeout(() => {
+ this.router.navigate(['/']);
+ }, 3000);
+ },
+ });
+ }
} else {
this.error = 'Authentication failed. No authorization code received.';
diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts
index 081ad72..61b3e7d 100644
--- a/frontend/src/app/service/auth.service.ts
+++ b/frontend/src/app/service/auth.service.ts
@@ -79,6 +79,15 @@ export class AuthService {
);
}
+ googleAuth(code: string): Observable
{
+ return this.http.post(`${this.oauthUrl}/google/callback`, { code }).pipe(
+ tap((response) => {
+ this.setToken(response.token);
+ this.loadCurrentUser();
+ })
+ );
+ }
+
logout(): void {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
From 52de53878e6f839003e0dd9e4c79d80cd82510ed Mon Sep 17 00:00:00 2001
From: Constantin Simonis
Date: Wed, 21 May 2025 11:35:29 +0200
Subject: [PATCH 005/136] style: fix formatting and add newlines at end of
files
---
.../casino/security/GoogleController.java | 2 +-
.../szut/casino/security/GoogleService.java | 2 +-
.../security/oauth2/GoogleOAuth2UserInfo.java | 2 +-
frontend/src/app/app.routes.ts | 4 ++--
.../feature/auth/login/login.component.html | 22 ++++++++-----------
5 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/backend/src/main/java/de/szut/casino/security/GoogleController.java b/backend/src/main/java/de/szut/casino/security/GoogleController.java
index 1d83cb2..2219d5d 100644
--- a/backend/src/main/java/de/szut/casino/security/GoogleController.java
+++ b/backend/src/main/java/de/szut/casino/security/GoogleController.java
@@ -46,4 +46,4 @@ public class GoogleController {
AuthResponseDto response = googleService.processGoogleCode(code);
return ResponseEntity.ok(response);
}
-}
\ No newline at end of file
+}
diff --git a/backend/src/main/java/de/szut/casino/security/GoogleService.java b/backend/src/main/java/de/szut/casino/security/GoogleService.java
index 306a1ab..703b85a 100644
--- a/backend/src/main/java/de/szut/casino/security/GoogleService.java
+++ b/backend/src/main/java/de/szut/casino/security/GoogleService.java
@@ -161,4 +161,4 @@ public class GoogleService {
throw new RuntimeException("Failed to process Google authentication", e);
}
}
-}
\ No newline at end of file
+}
diff --git a/backend/src/main/java/de/szut/casino/security/oauth2/GoogleOAuth2UserInfo.java b/backend/src/main/java/de/szut/casino/security/oauth2/GoogleOAuth2UserInfo.java
index 9b31294..66fc99c 100644
--- a/backend/src/main/java/de/szut/casino/security/oauth2/GoogleOAuth2UserInfo.java
+++ b/backend/src/main/java/de/szut/casino/security/oauth2/GoogleOAuth2UserInfo.java
@@ -22,4 +22,4 @@ public class GoogleOAuth2UserInfo extends OAuth2UserInfo {
public String getEmail() {
return (String) attributes.get("email");
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts
index 2db4310..ea7821a 100644
--- a/frontend/src/app/app.routes.ts
+++ b/frontend/src/app/app.routes.ts
@@ -39,7 +39,7 @@ export const routes: Routes = [
import('./feature/auth/oauth2/oauth2-callback.component').then(
(m) => m.OAuth2CallbackComponent
),
- data: { provider: 'github' }
+ data: { provider: 'github' },
},
{
path: 'oauth2/callback/google',
@@ -47,7 +47,7 @@ export const routes: Routes = [
import('./feature/auth/oauth2/oauth2-callback.component').then(
(m) => m.OAuth2CallbackComponent
),
- data: { provider: 'google' }
+ data: { provider: 'google' },
},
{
path: 'game/blackjack',
diff --git a/frontend/src/app/feature/auth/login/login.component.html b/frontend/src/app/feature/auth/login/login.component.html
index 54097c9..338da91 100644
--- a/frontend/src/app/feature/auth/login/login.component.html
+++ b/frontend/src/app/feature/auth/login/login.component.html
@@ -106,30 +106,26 @@
Mit GitHub anmelden
-
+
`,
})
-export class OAuth2CallbackComponent implements OnInit {
+export default class OAuth2CallbackComponent implements OnInit {
error: Signal