@latitude-data/jwt
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@latitude-data/jwt

Latitude's JWT library. It's a simple library to generate and verify JWT tokens. Under the hood is using jose library.

Installation

npm add @latitude-data/jwt

Usage for signing a token

import { signJwt } from '@latitude-data/jwt'

const token = await signJwt({
  payload: { company_id: 1, admin: true },
  secretKey: '[LATITUDE_SECRET]',
  expiresIn: '2h', // Optional, by default is 2h
})

Usage for verifying a token

import { verifyJwt } from '@latitude-data/jwt'

const token '[SIGNED_JWT_TOKEN_ABOVE]' ☝️

const response = await veryfyJwt({
  secretKey: '[LATITUDE_SECRET]',
  token,
})

if (response instanceof Error) {
  console.log('Do something with the error')
}

const { payload } = response

// payload = { company_id: 1, admin: true }

Readme

Keywords

none

Package Sidebar

Install

npm i @latitude-data/jwt

Weekly Downloads

129

Version

0.2.0

License

LGPL

Unpacked Size

14.9 kB

Total Files

12

Last publish

Collaborators

  • gerardclos
  • csansoon
  • cesr
  • andresgutgon