Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can´t retrieve access token in login response headers #877

Closed
JulianSansat opened this issue May 1, 2017 · 1 comment
Closed

Can´t retrieve access token in login response headers #877

JulianSansat opened this issue May 1, 2017 · 1 comment

Comments

@JulianSansat
Copy link

I'm implementing a ionic 2 client to use the rails api, already got the user´s registration working, but the problem is the login, the rails app sends the "OK" response with the headers, but I´m having trouble to retrieve the access-token from the headers because the json is all nested in a strange way, and I didn´t override nothing, is the default devise token auth response.
https://i.stack.imgur.com/WtfXv.png
http://stackoverflow.com/questions/43714404/retrieve-access-token-from-devise-auth-response-headers

login(credentials) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        this.http.post(apiUrl+'auth/sign_in', JSON.stringify(credentials), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            console.log(err);
          });
    });
  }

the response is getting null or undefined. Viewing on the print the way the response is nested could be the reason that the function can´t reach de access-token value.

I´m wonder what i´m doing wrong, because with the Angular2-token (which is not compatible with ionic) it doesn´t need to get the values from a nested json.
Thanks

@JulianSansat
Copy link
Author

JulianSansat commented May 1, 2017

I figured out already, it was sending the response as a json, so on the other component i wasn´t able to use de http methods, so i used res.headers.get('access-token') with de http lib of angular, and did the trick. I´m implementing an ionic client because, there is no suport yet for an ionic mobile solution with devise token auth, I hope I can implement the rest of the features and share the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant