import { Component, inject, signal, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { AuthService } from '../../core/services/auth.service'; import { ToastService } from '../../core/services/toast.service'; @Component({ selector: 'app-oauth-callback', standalone: true, template: `
@if (error()) {

Authentication Failed

{{ error() }}

Back to Login } @else {

Signing you in...

Please wait while we complete authentication

}
`, }) export class OAuthCallbackComponent implements OnInit { private authService = inject(AuthService); private router = inject(Router); private toastService = inject(ToastService); error = signal(null); ngOnInit(): void { this.handleCallback(); } private handleCallback(): void { const params = new URLSearchParams(window.location.search); const accessToken = params.get('accessToken'); const refreshToken = params.get('refreshToken'); const sessionId = params.get('sessionId'); const errorParam = params.get('error'); if (errorParam) { this.error.set(decodeURIComponent(errorParam)); return; } if (!accessToken || !refreshToken || !sessionId) { this.error.set('Missing authentication tokens'); return; } // Store the tokens and redirect this.authService.handleOAuthCallback(accessToken, refreshToken, sessionId); this.toastService.success('Welcome!'); this.router.navigate(['/dashboard']); } }