-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestToken.js
More file actions
25 lines (22 loc) · 795 Bytes
/
testToken.js
File metadata and controls
25 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const jwt = require('jsonwebtoken')
require('dotenv').config()
const jwtTest = async () => {
try {
// simulate a server response when a user is logged in
// create jwt paload
const payload = {
name: 'hi im a user',
id: 'jklhf3245jklhdsf',
// password???? -- NO
email: 'email@domain.com'
}
// sign the jwt token
const secret = 'my secret that the token is signed with, this is like a password'
const token = jwt.sign(payload, secret, { expiresIn: (60 * 60) * 24 }) // exprires in is how long the token is good for in minutes
// decode the jwt -- make sure that the secret in the jwt is the same as our server's secret
const decode = jwt.verify(token, process.env.JWT_SECRET)
} catch (err) {
console.log(err)
}
}
jwtTest()