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
Showing only changes of commit 756beb5a4e - Show all commits

View file

@ -29,17 +29,14 @@ export class OAuth2CallbackComponent implements OnInit {
) {}
ngOnInit(): void {
// 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) {
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) => {
@ -47,17 +44,14 @@ export class OAuth2CallbackComponent implements OnInit {
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 {
// 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) => {
@ -65,7 +59,6 @@ export class OAuth2CallbackComponent implements OnInit {
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);
@ -75,7 +68,6 @@ export class OAuth2CallbackComponent implements OnInit {
} else {
this.error = 'Authentication failed. No authorization code received.';
// Redirect back to landing page after showing error
setTimeout(() => {
this.router.navigate(['/']);
}, 3000);