@@ 8,27 8,27 @@ description = "JSON Web Token implementation for Node.js."
keywords = "JWT, Node JWT, JSON Web Token, JWT sign, JWT verify, crypto"
+++
-I have written a JavaScript library to sign and verify JSON Web Tokens. It has no dependencies and at the moment works only with HMAC SHA256.
+I have written a JavaScript library to sign and verify JSON Web Tokens. It has no dependencies and at the moment works only with HMAC SHA algorithms.
```js
import jwt from '@onelastjedi/node-jwt'
const secret = process.env.__SECRET__
-const data = {
- exp: Math.floor(Date.now() / 1000) + 60 * 60,
- user: { id: 1, name: 'Mary' }
+const data = {
+ exp: 60 * 60 * 24 * 7, // 7 days
+ user: { id: 1, name: 'Mary' }
}
jwt.sign(data, secret) // eyJhbGc.....
jwt.verify(token, secret)
-/*
- {
- alg: 'HS256',
- typ: 'JWT',
- user: { id: 1, name: 'Mary' },
- iat: ...,
- exp: ...,
+/*
+ {
+ alg: 'HS256',
+ typ: 'JWT',
+ user: { id: 1, name: 'Mary' },
+ iat: ...,
+ exp: ...,
}
*/
```