Created
December 1, 2018 03:08
-
-
Save meshboy/fa7f78d38659ea19f939c86f5cce0871 to your computer and use it in GitHub Desktop.
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 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