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 { ngOnInit(): void {
// Check for code in URL params
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
const code = params['code']; const code = params['code'];
const provider = this.route.snapshot.data['provider'] || 'github'; const provider = this.route.snapshot.data['provider'] || 'github';
if (code) { if (code) {
if (provider === 'google') { if (provider === 'google') {
// Exchange Google code for a JWT token
this.authService.googleAuth(code).subscribe({ this.authService.googleAuth(code).subscribe({
next: () => { next: () => {
// Redirect to home after successful authentication
this.router.navigate(['/home']); this.router.navigate(['/home']);
}, },
error: (err) => { error: (err) => {
@ -47,17 +44,14 @@ export class OAuth2CallbackComponent implements OnInit {
this.error = err.error?.message || 'Authentication failed. Please try again.'; this.error = err.error?.message || 'Authentication failed. Please try again.';
console.log('Error details:', err); console.log('Error details:', err);
// Redirect back to landing page after showing error
setTimeout(() => { setTimeout(() => {
this.router.navigate(['/']); this.router.navigate(['/']);
}, 3000); }, 3000);
}, },
}); });
} else { } else {
// Exchange GitHub code for a JWT token
this.authService.githubAuth(code).subscribe({ this.authService.githubAuth(code).subscribe({
next: () => { next: () => {
// Redirect to home after successful authentication
this.router.navigate(['/home']); this.router.navigate(['/home']);
}, },
error: (err) => { error: (err) => {
@ -65,7 +59,6 @@ export class OAuth2CallbackComponent implements OnInit {
this.error = err.error?.message || 'Authentication failed. Please try again.'; this.error = err.error?.message || 'Authentication failed. Please try again.';
console.log('Error details:', err); console.log('Error details:', err);
// Redirect back to landing page after showing error
setTimeout(() => { setTimeout(() => {
this.router.navigate(['/']); this.router.navigate(['/']);
}, 3000); }, 3000);
@ -75,7 +68,6 @@ export class OAuth2CallbackComponent implements OnInit {
} else { } else {
this.error = 'Authentication failed. No authorization code received.'; this.error = 'Authentication failed. No authorization code received.';
// Redirect back to landing page after showing error
setTimeout(() => { setTimeout(() => {
this.router.navigate(['/']); this.router.navigate(['/']);
}, 3000); }, 3000);