I am trying to call an http GET method to check if the user has a session with my back end NodeJS API, but I can't see the request being made.
I have an observable that is set when the user logs in so my AuthGuard will check this first, if this is set to false then call the back end to see if there is an existing session.
auth.guard.ts
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
this.authService.loggedIn.subscribe(currentState => {
this.loggedIn = currentState;
});
if (this.loggedIn) {
return true;
} else {
console.log('check for login');
this.http.get(environment.apiURL + '/checklogin'
, { withCredentials : true }
).map(user => {
const resp = user.json();
// login successful if there's a user
if (resp.isLoggedIn) {
this.authService.obsLoggedIn.next(true);
return true;
} else {
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
console.log('about to return false for authguard');
return false;
}
});
}
}
app.js
app.get('/checklogin', function(req, res) {
console.log('get from login ' + req.body);
req.session.user ? res.status(200).send({isLoggedIn: true}) : res.status(200).send({isLoggedIn: false});
});
I know there is nothing wrong with my apiURL since going to the login page and logging in works fine, and I can see back-end logging.
Can anyone see why my http request would not work?