Skip to content

Instantly share code, notes, and snippets.

@iMichaelOwolabi
Last active September 30, 2022 18:08
Show Gist options
  • Save iMichaelOwolabi/94d5a7282fe813b5bcffe970a35b93bc to your computer and use it in GitHub Desktop.
Save iMichaelOwolabi/94d5a7282fe813b5bcffe970a35b93bc to your computer and use it in GitHub Desktop.
jwt helper code
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