I have a simple login where you enter email and password and if it is available in the DB, the user can log in. But as logged in user must redirect to specific pages.
for example: If the user login type is 'supplier' user must redirect to a specific page while if not the user must redirect to another page.
This is the service method
login(email, password): any {
const headers = new HttpHeaders({
'Content-Type': 'application/json'
});
return this.http
.post(this.uri + '/login', { email, password }, {headers})
.pipe(catchError(this.errorHandler));
}
I would like to redirect to the dashboard, if user is not type 'supplier'
this.router.navigate(['dashboard']);
I would like to redirect to the 'supplier' if the user is a supplier
this.router.navigate(['supplier']);
The user object from backend is as follows
error: false
result:
email: "[email protected]"
phone_no: "00000008"
type: "supplier"
user_id: 1
For ref, This is the ts file method
loginToSystem(): any {
const email = this.formData().email;
const password = this.formData().password;
this.backendService.login(email, password)
.subscribe(data => {
this.loginData = data;
console.log(data);
// console.log('helo');
console.log(data.result.type);
});
console.log(email, password);
}
app.routing
const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{path: 'login', component: LoginComponent},
{path: 'dashboard', component: DashboardComponent},
{path: 'supplier', component: SupplierComponent}
];
appreciate any insight on this matter! Thanks!