Answer the question
In order to leave comments, you need to log in
Why does it redirect to the root page after authentication check?
Created a canActivate file and method
detect: boolean;
canActivate(): boolean {
this.myHttp.getHTTP('http://localhost:3000/detect')
.subscribe( (data: any) => {
this.detect = data.detect;
}, err => {
if (err instanceof HttpErrorResponse && err.status === 401) {
this.detect = false;
}
})
if (this.detect === false) {
this._router.navigate(['/login']);
return this.detect;
}
return true;
}
const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'newlead', component: NewLeadComponent, canActivate: [AuthGuard] },
{ path: 'leadlist', component: LeadListComponent, canActivate: [AuthGuard] },
{ path: 'leadlist/:id', component: LeadPageComponent, canActivate: [AuthGuard] },
];
router.get('/detect', function( req, res) {
if ( req.isAuthenticated() ) {
res.status(200).send({ detect: true })
} else {
res.status(401).send({ detect: false })
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question