juw
v1.0.6
Published
Type safe jwt usage
Downloads
3
Maintainers
Readme
Juw
type safe jwt usage
Features
- type safe
- give secret only once
Quick Start
import { initJwtService } from 'juw';
import { IUser } from './your.user.interface';
const userJwtService = initJwtService<IUser>(YOUR_SECRET_KEY);
const token = userJwtService.sign(
payloadToSign /* must be of type IUser */,
opts /* jsonwebtoken SignOptions */
);
const decoded = userJwtService.decode(
token,
opts /* jsonwebtoken DecodeOptions */
);
// decoded is now of type IUser!
import { initJwtService } from 'juw';
import { ISession } from './your.session.interface';
const sessionJwtService = initJwtService<ISession>(YOUR_SECRET_KEY)
...
const decoded = sessionJwtService.decode(token, opts)
// decoded is now of type ISession!