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

Post-login behaviour (for items requiring token) #19

Open
yarnball opened this issue Nov 12, 2016 · 0 comments
Open

Post-login behaviour (for items requiring token) #19

yarnball opened this issue Nov 12, 2016 · 0 comments

Comments

@yarnball
Copy link

Hi,

So I'm getting my token on the actions.js page by doing this:

localStorage.setItem('id_token', JSON.stringify(user.token).replace(/\"/g, ""))

Then in Quotes.js, I've got some custom code (with a fetch).

However, the Quotes.js seems to get called even before the user is logged in. This creates a problem as my 'fetch` requires the token that is created at the login page.

The only way I can get it working is to refresh the page.

Is there a way around this?

I tried adding react-router but this didn't help.

Here's a sample of Quotes.js

componentWillMount () {
    return fetch(DATA_API, 
      {
      headers: {
        'Authorization': 'JWT  ' + localStorage.getItem('id_token'),
        'Content-Type': 'application/json'}
      }
      )
      .then((response) => response.json())
      .then((json) => {
        this.setState({testapi: json, uniqueCategories: this.getUniqueCategories(json) })
      })
    },
@yarnball yarnball changed the title Get files that require token to load after the login Post-login behaviour (for items requiring token) Nov 12, 2016
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