Skip to content

Instantly share code, notes, and snippets.

@meshboy
Created December 1, 2018 03:08
Show Gist options
  • Select an option

  • Save meshboy/fa7f78d38659ea19f939c86f5cce0871 to your computer and use it in GitHub Desktop.

Select an option

Save meshboy/fa7f78d38659ea19f939c86f5cce0871 to your computer and use it in GitHub Desktop.
const secret = process.env.TOKEN_SECRET;
const expiresIn = process.env.EXPIRES_IN || '1 day';
export const signIn = payload => jsonwebtoken.sign(payload, secret, { expiresIn });
export const verify = token => {
return new Promise((resolve, reject) => {
jsonwebtoken.verify(token, secret, {}, (err, payload) => {
if(err){
return reject(err);
}
return resolve(payload);
})
})
}
export const throwErrorIfUserNotAuthenticated = user =>
{if(!user) throw new Error('hey!. You are not authenticated')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment