~onelastjedi/phon.one

7f67e17d0a47671dee019373d4d6b3af0f3a7b86 — J.D 1 year, 1 month ago 1c7e367 main
Update post
1 files changed, 11 insertions(+), 11 deletions(-)

M content/node-jwt.md
M content/node-jwt.md => content/node-jwt.md +11 -11
@@ 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: ...,
    }
*/
```