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

Handle error jwtDecode #4

Open
dciccale opened this issue Nov 3, 2016 · 1 comment
Open

Handle error jwtDecode #4

dciccale opened this issue Nov 3, 2016 · 1 comment

Comments

@dciccale
Copy link

dciccale commented Nov 3, 2016

https://github.com/Remchi/reddice/blob/master/client/index.js#L24

jwtDecode can throw an error if a not valid token is passed, how do you suggest handling this?

for now I've created utils/decodeToken.js with:

import jwtDecode from 'jwt-decode';

export default function decodeToken(token) {
  let decoded = {};
  try {
    decoded = jwtDecode(token);
  } catch (err) {
  }
  return decoded;
};

and in index.js just call it instead of jwtDecode

import decodeToken from './utils/decodeToken';
...
store.dispatch(setCurrentUser(decodeToken(localStorage.jwtToken)));
@dciccale
Copy link
Author

dciccale commented Nov 3, 2016

However I think if it fails, something has to happen, like a redirect or clean up of the invalid token ?

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