Skip to content

Instantly share code, notes, and snippets.

@LukeMwila
Created April 20, 2019 17:51
Show Gist options
  • Save LukeMwila/dfb1217fe401ca86ba06f2c381a49ed0 to your computer and use it in GitHub Desktop.
Save LukeMwila/dfb1217fe401ca86ba06f2c381a49ed0 to your computer and use it in GitHub Desktop.
Check if a token is valid
const isTokenValid = (token: string | null): boolean => {
if (!token) {
return false;
}
try {
const decodedJwt: any = decode(token);
return decodedJwt.exp >= Date.now() / 1000;
} catch (e) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment