-
-
Save iMichaelOwolabi/94d5a7282fe813b5bcffe970a35b93bc to your computer and use it in GitHub Desktop.
jwt helper code
This file contains 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
import jwt from 'jsonwebtoken'; | |
import { config } from 'dotenv'; | |
config(); | |
export const generateToken = async payload => { | |
return await jwt.sign(payload, process.env.JWTSECRET, { | |
expiresIn: parseInt(process.env.TOKENEXPIRATIONTIME, 10), | |
}); | |
}; | |
export const jwtValidator = async token => { | |
try { | |
const decodedToken = await jwt.verify(token, process.env.JWTSECRET,); | |
return decodedToken; | |
} catch (error) { | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment