loopback-sdk-builder
loopback-sdk-builder copied to clipboard
catching 401 errors
What type of issue are you creating?
- [ ] Bug
- [ ] Enhancement
- [x] Question
What version of this module are you using?
- [ ] 2.0.10 (Stable)
- [x] 2.1.0-rc.n (2.1 Release Candidate n)
- [ ] Other
I am trying to move from a jwt-based auth system to using standard loopback auth with passport and a local strategy
Whilst the backend is working (I can log in with explorer and access the api) I'm not entirely sure how to go about integrating this into my angular4 app
So, I login, get this data back ..
{
"id": "TBEauxIDQlLMlnKXsiH6ssf6FOFT4KjugoEOeQ67tfx2pK4IcoH03SwQPmmyc9eN",
"ttl": 1209600,
"created": "2017-08-31T19:09:23.189Z",
"userId": 2
}
how do I a) save it, and b) send it with every request ?
Another , related topic - if I am not logged in and the app tries to make an api call using the base .find() I (obviously) get a 401 . How can I be notified of this 401 and force a login ?
so I've followed the "social passport" example , added
import { LoopBackAuth } from '../sdk/services';
[snip]
constructor(
private _lbAuth: LoopBackAuth, ...
[snip]
private setToken(token) {
this._lbAuth.setToken(token);
this._lbAuth.setRememberMe(true);
this._lbAuth.save();
};
but any api requests do not have the access_token query parameter
a) can I change access_token to an http header ? b) can I add some custom headers to all outbound requests ?
any answer ?