Nebular: anth:how to get response from backend

Created on 22 Sep 2017  路  5Comments  路  Source: akveo/nebular

in nebular/auth:
if login success , the backend would return a token , how can i get the token or other response?

faq question

Most helpful comment

@jogamod, @jomalonejia currently there is no out of the box way to get a complete result of auth http requests, but you can simply use Angular Http Interceptors to intercept any request and modify or store a call result, check out this article https://alligator.io/angular/httpclient-interceptors/
in your interceptor you can call the do function:

return next.handle(req).do(evt => {
      if (evt instanceof HttpResponse) {
        // here you can get the body from evt and store it 
      }
    });

All 5 comments

Hey @jomalonejia, I updated the documentation on the NbAuthToken service which provides you with access to the stored token https://akveo.github.io/nebular/#/docs/auth/nbtokenservice. Let me know if this helps.

How to get other data from server response? Example: i want "user" from this json response ->{"token":"573bc352fd093609234a610782edd3f2fa393ef3","user":{"url":"http://localhost:8000/api/users/7/","username":"foo","email":"[email protected]","first_name":"A","last_name":"B"}}

@nnixaa Hi nnixaa it worked , i can get the stored token . thanks a lot .
if stored other response data , is there any service to get that

@jogamod
i can get the response by this way,
but i dont know if this is a correct callback function

messages: {
key: 'data.messages',
getter: (module: string, res: HttpResponse) => {
console.log(res.body);
}
},

@jogamod, @jomalonejia currently there is no out of the box way to get a complete result of auth http requests, but you can simply use Angular Http Interceptors to intercept any request and modify or store a call result, check out this article https://alligator.io/angular/httpclient-interceptors/
in your interceptor you can call the do function:

return next.handle(req).do(evt => {
      if (evt instanceof HttpResponse) {
        // here you can get the body from evt and store it 
      }
    });
Was this page helpful?
0 / 5 - 0 ratings