I have a problem trying to display a loading message linked to the server response, I managed to do it right for the logout method but I don't know how to do it for the login. Here is the code for my account service.
login(email: string, password: string) {
return this.http
.post<User>(
environment.apiUrl + '/auth/login',
{
email: email,
password: password
})
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in 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!');
});
}
}