why login not working after form submission ?

login.ts :
`async onSubmit(): Promise {
this.email = true;
this.pwd = true;
this.mailform = true;
this.isLoginInProgress.set(true);

this._authService .login(this.form.controls.email.value.trim(), this.form.controls.password.value.trim()) .pipe( catchError((error: HttpErrorResponse) => { this.handleAuthError(error); return of(error); }), tap(response => this._handleLogin(response)), finalize(() => this.isLoginInProgress.set(false)) ) .subscribe({ error: (error) => { console.error('Login error:', error); } });
Enter fullscreen mode
Exit fullscreen mode

}

private _handleLogin(response: any): void {
if (!response?.user) return;
this.login = true;
const accessToken = response.user.accessToken;
const user_uid = response.user.uid;
localStorage.setItem(‘accessToken’, accessToken);
localStorage.setItem(‘user_uid’, user_uid);
window.location.reload();
this._router.navigateByUrl(‘/dashboard’);

}

handleAuthError(err: HttpErrorResponse): void {
if (!err.error.code) return;

this.authError.set(true);
this.form.valueChanges .pipe( take(1), tap(() => this.authError.set(true)) ) .subscribe();
Enter fullscreen mode
Exit fullscreen mode

}
`

login.html :
<form [formGroup]="form" (ngSubmit)="onSubmit()" class="form-detail">
</form>

authservice.ts :
`login(email: string, password: string): Observable {
console.log(‘Logging in user:’, email);
const promise = signInWithEmailAndPassword(this.firebaseAuth, email, password)
.then(response => {
console.log(‘Login successful:’, response);
return response;
})
.catch(error => {
console.error(‘Login error:’, error);
throw error;
});

return from(promise);
Enter fullscreen mode
Exit fullscreen mode

}
`


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Our web pages and their contents are subject to copyright law. Image composite editor (64 bit). 2025 jamb questions and answers |free 2025 jamb answers.