Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Caching Authorization Token for future re-use #58

Closed
gkatsanos opened this issue Sep 29, 2017 · 3 comments
Closed

Caching Authorization Token for future re-use #58

gkatsanos opened this issue Sep 29, 2017 · 3 comments

Comments

@gkatsanos
Copy link

gkatsanos commented Sep 29, 2017

Hello,

I am trying to figure out https://jsfiddle.net/robinvdvleuten/wmf8zvf8/ .
Is there a logic hidden somewhere that takes the localStorage if available ?
I am using the plugin to store a JWT (Authorization token) and as I am explicitly doing:

const state = JSON.parse(localStorage.getItem('persistedState'));
const config = {
  headers: {
    Authorization: `Bearer ${state.tokens.token.accessToken}`,
  },
};

I get errors when localStorage is empty.
Naturally I could add a condition to check for that but from your example it seems that's already part of the plugin.

@gkatsanos gkatsanos changed the title More advanced example More advanced case / how does the magic happen Sep 29, 2017
@gkatsanos gkatsanos changed the title More advanced case / how does the magic happen Caching Authorization Token for future re-use Sep 29, 2017
@robinvdvleuten
Copy link
Owner

Could you please describe your error somewhat more? Is an API error, localstorage error, etc?

@gkatsanos
Copy link
Author

Hey Robin, Yeah I think it was a misunderstanding from my part.
In order for the persisted state to work, do you need to keep a default (empty string, null, default) value in your store/index.js ?

@robinvdvleuten
Copy link
Owner

@gkatsanos yes correctly, you'll need a default "initial state" for your store.

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

No branches or pull requests

2 participants