Currently facing an issue with displaying a loading message that is connected to the server response. I was able to implement this successfully for the logout function but am struggling with it for the login function. Below is the code snippet from my account service:
login(email: string, password: string) {
return this.http
.post<User>(
environment.apiUrl + '/auth/login',
{
email: email,
password: password
})
.pipe(map(user => {
// Storing user details and JWT token in local storage to maintain logged-in state between page refreshes
localStorage.setItem('scrb-user', JSON.stringify(user));
this.userSubject.next(user);
return user;
}));
}
signup(user: User) {
return this.http
.post<User>(
environment.apiUrl + '/auth/signup',
user
);
}
logout() {
this.message
.loading('Action in progress', { nzDuration: 2000 })
.onClose!.pipe(
concatMap(() => this.message.success('Loading finished', { nzDuration: 2000 }).onClose!),
// concatMap(() => this.message.info('Loading finished is finished', { nzDuration: 2000 }).onClose!)
)
.subscribe(() => {
localStorage.removeItem('scrb-user');
this.userSubject.next(null);
this.router.navigate(['/account/login']);
console.log('All completed!');
});
}
}