question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All the values stored in localStorage are undefined

See original GitHub issue

I am getting back the access tokens and everything back right from Devise Auth Token right, but when storing those into the localStorage, it is storing undefined and hence every other verifyToken is failing.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
andrewmartincommented, May 6, 2018

@AmitJoki

BOOM. I figured out what was going on after debugging and trying to write my own handler…

In my app’s configuration, the headers were not being exposed.

This is pretty critical; @kylecorbelli I might recommend adding some notes to the README (or I can open a quick PR), it was something really confusing and easy to miss.

I’m using Rack::Cors:

    config.middleware.insert_before 0, Rack::Cors do
      allow do
        origins '*'
        resource '*', :headers => :any, :methods => [:get, :post, :delete, :put, :patch, :options, :head], :expose  => ['uid', 'client', 'expiry', 'access-token', 'token-type']
      end
    end

The important configuration here is this: :expose => ['uid', 'client', 'expiry', 'access-token', 'token-type']

Without this, the headers aren’t actually provided to the Client in the Response; though they’re visible in developer tools and such, the browser can’t access them.

Once I added this to my Rails app, everything worked like a breeze.

Hope this helps!

0reactions
AmitJokicommented, May 8, 2018

I haven’t gotten exactly to the bottom of the issue, but switching over to a fork of this, by joshuadev fixed my problem. Try installing hs fork of the npm package.

Sent from my Redmi 4 On Peter Lawless notifications@github.com, 8 May 2018 10:02 pm wrote:

Still having this issue, even with the rack-cors configuration. After confirming my account via email, I am redirected to the success url and I can see access-token, client, client_id, token, expiry, etc, all in the query string parameters. But when the client kicks off a request to verify the token, all the parameters are undefined and the request returns a 401. It may also be worth noting that my client and server reside on the same domain? Please help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/kylecorbelli/redux-token-auth/issues/39#issuecomment-387463188, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AE62mhMikVTe03GbCv8HMmwWsjG3FOKEks5twciwgaJpZM4Tz3de.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is localStorage["..."] undefined, but localStorage.getItem ...
In javascript you always get an undefined value for keys that does not exist inside an object. a = {}; //new object alert(a["test"]);...
Read more >
localStorage returning undefined - Hashnode
When setting (saving) objects in the localStorage, the API will always return undefined - you are doing everything all right. Also, it can...
Read more >
Why does localStorage.getItem() return undefined? - Reddit
getItem() return undefined? Everything I'm reading says localStorage is synchronous. And there's no promise returned.
Read more >
Storage.setItem() - Web APIs - MDN Web Docs
A string containing the value you want to give the key you are creating/updating. Return value. None ( undefined ). Exceptions. setItem() ...
Read more >
Local Storage
The localStorage object provides a key-value database — think JavaScript object, which maps keys (a.k.a. fields, property names) to values — for use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found