Created
April 20, 2019 17:51
-
-
Save LukeMwila/dfb1217fe401ca86ba06f2c381a49ed0 to your computer and use it in GitHub Desktop.
Check if a token is valid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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