@dupkey/jwt
v2.0.0
Published
Create an access token, refresh token, and verify.
Downloads
8
Readme
@dupkey/jwt
Create an access token, refresh token, and verify. Implements jsonwebtoken
Install
npm install @dupkey/jwt
Example
import Jwt from '@dupkey/jwt';
let jwt = new Jwt('ACCESS_SECRET', 'REFRESH_SECRET');
let accessToken = jwt.accessToken({ id: 123 });
let refreshToken = jwt.refreshToken({ id: 123 });
return jwt.verifyAccessToken(accessToken);
Methods
Use these methods to interact with the library:
accessToken(payload: object = {}, expiresIn: string = '1h'): string
: Sign and return an access token.refreshToken(payload: object = {}, expiresIn: string = '7d'): string
: Sign and return a refresh token.verifyAccessToken(jwt: string): string
: Verify the access token.verifyRefreshToken(jwt: string): string
: Verify the refresh token.
Build the TypeScript and JavaScript versions
npm run build
Run the tests
npm test
VS Code Debugging
Create a launch.json
file in your .vscode folder with the following:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require", "ts-node/register",
"-u", "tdd",
"--timeout", "999999",
"--colors", "--recursive",
"${workspaceFolder}/test/**/*.ts"
],
"internalConsoleOptions": "openOnSessionStart"
}
]
}
In the debug tab (Ctrl+Shift+D) select "Mocha Tests" from the dropdown and then click "Start Debugging". Results will display in the console on the bottom of the VS Code.