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

React Error Appearing After Web Token Expiration #496

Closed
caioingber opened this issue Apr 3, 2020 · 0 comments · Fixed by #510
Closed

React Error Appearing After Web Token Expiration #496

caioingber opened this issue Apr 3, 2020 · 0 comments · Fixed by #510
Assignees
Labels
authentication related to authentication implementation bug Something isn't working

Comments

@caioingber
Copy link
Contributor

Describe the bug
It appears that when a user's JWT expires locally, the token is neither refreshed if they are still actively logged in or logged out due to inactivity.

To Reproduce
Steps to reproduce the behavior:
Login or register at root url. Stay logged in for at least 10hrs, attempt to refresh the browser at any page in the application and the error should appear.

Expected behavior
User should be redirected to main login page or token should be refreshed if user has not actively logged out.

Screenshots
Screen Shot 2020-04-03 at 15 46 06

Additional context
It appears that part of the issue stems from the conditional that is presented inside the ComponentDidMount() portion of the App.js file:

  componentDidMount() {
    if (this.state.logged_in) {
      fetch("http://localhost:8000/auth/user", {
        headers: {
          Authorization: `Token ${localStorage.getItem("token")}`
        }
      })
        .then(res => res.json())
        .then(json => {
          console.log(json);
          this.setState({
            email: json.email,
            first_name: json.profile.first_name,
            image: json.profile.image
          });
        });
    }
  }

Because a user is technically 'logged_in' when the token expires it returns the error because there is no user information to attempt to setState for. Not sure if the issue lies more on the frontend or backend or both.

@caioingber caioingber added bug Something isn't working authentication related to authentication implementation labels Apr 3, 2020
@caioingber caioingber self-assigned this Apr 6, 2020
@caioingber caioingber linked a pull request Apr 6, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
authentication related to authentication implementation bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant