Hi guys, I’m working with authentication of my app wherein I was handling three different types of account. My question is, how I can identify the account type of the recently logged user? In my case, I was trying to determine if the user is clinician, clinician instructor or patient. Each of these has its own dashboard where they will redirected.
Here is my code:
app.component.ts
this.authenticationService.authenticationState.subscribe(state => {
if(state){
this.authenticationService.isClinician.subscribe(clinician => {
if(clinician){
this.router.navigate(['members', 'menu', 'clinician-dashboard']);
console.log('clinician')
}
});
this.authenticationService.isInstructor.subscribe(instructor => {
if(instructor){
this.router.navigate(['members', 'instructor-dashboard'])
console.log('instructor')
}
});
this.authenticationService.isPatient.subscribe(patient => {
if(patient){
this.router.navigate(['members', 'patient-dashboard'])
console.log('patient')
}
});
} else {
this.router.navigate(['login']);
console.log('User has not authenticated yet.')
}
});
authentication.service.ts please note that this is same for all account types.
loginAsClinician(data) {
return this.httpClient.post(this.url+'authenticate/clinicians', JSON.stringify(data), httpOptions)
.pipe( tap(res => {
// this.storageService.storage.clear();
this.success = true;
this.authenticationState.next(true);
this.isClinician.next(true);
this.storageService.setObject('clinician', res);
})
)
.toPromise();
}
Anyone know how to work with authentication of multiple accounts? Thanks.