import { Component, computed, inject, signal } from '@angular/core'; import { RouterLink } from '@angular/router'; import { firstValueFrom } from 'rxjs'; import { AuthService, isValidEmail } from '@africanies/africanies-core'; import { AlertComponent, ButtonComponent, TextInputComponent, } from '@africanies/africanies-ui'; import { playgroundErrorMessage } from './playground-notify'; /** * Live {@link AuthService.forgot} try-out for the SDK API page. */ @Component({ selector: 'app-playground-forgot-password', standalone: true, imports: [AlertComponent, ButtonComponent, TextInputComponent, RouterLink], template: `

Try it

We will send you a password reset link.

@if (successMessage(); as ok) { Reset completed? Login here } @else { @if (errorMessage(); as err) { }
} `, }) export class PlaygroundForgotPasswordComponent { private readonly authApi = inject(AuthService); protected readonly email = signal(''); protected readonly sending = signal(false); protected readonly successMessage = signal(null); protected readonly errorMessage = signal(null); protected readonly canSubmit = computed( () => isValidEmail(this.email()) && !this.sending(), ); protected async forgot(): Promise { if (!this.canSubmit()) { return; } this.sending.set(true); this.errorMessage.set(null); try { const res = await firstValueFrom(this.authApi.forgot(this.email())); if (res.success) { this.successMessage.set( res.message?.trim() || 'We have emailed your reset password.', ); return; } this.errorMessage.set( res.message?.trim() || 'Could not send a reset email.', ); } catch (err) { this.errorMessage.set(playgroundErrorMessage(err)); } finally { this.sending.set(false); } } }