import { CommonModule } from '@angular/common'; import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, RouterModule } from '@angular/router'; import { environment } from '../../../environments/environment'; import { AuthService } from '../../services/auth.service'; import { UserService } from '../../services/user.service'; @Component({ selector: 'app-email-authorized', standalone: true, imports: [CommonModule, RouterModule], templateUrl: './email-authorized.component.html', }) export class EmailAuthorizedComponent implements OnInit { verificationStatus: 'pending' | 'success' | 'error' = 'pending'; errorMessage: string | null = null; constructor(private route: ActivatedRoute, private http: HttpClient, private authService: AuthService, private userService: UserService) {} ngOnInit(): void { const oobCode = this.route.snapshot.queryParamMap.get('oobCode'); const email = this.route.snapshot.queryParamMap.get('email'); const mode = this.route.snapshot.queryParamMap.get('mode'); if (mode === 'verifyEmail' && oobCode && email) { this.verifyEmail(oobCode, email); } else { this.verificationStatus = 'error'; this.errorMessage = 'Invalid verification link'; } } private verifyEmail(oobCode: string, email: string): void { this.http.post(`${environment.apiBaseUrl}/bizmatch/auth/verify-email`, { oobCode, email }).subscribe({ next: async () => { this.verificationStatus = 'success'; //await this.authService.refreshToken(); await this.authService.refreshUserClaims(); const user = await this.userService.getByMail(email); }, error: err => { this.verificationStatus = 'error'; this.errorMessage = err.error?.message || 'Verification failed'; }, }); } }