Démarrage rapide
Installation des dépendances
bash
npm install @duplojs/json-web-token@0 @duplojs/utils@1bash
yarn add @duplojs/json-web-token@0 @duplojs/utils@1bash
pnpm add @duplojs/json-web-token@0 @duplojs/utils@1bash
bun add @duplojs/json-web-token@0 @duplojs/utils@1bash
deno add npm:@duplojs/json-web-token@0 npm:@duplojs/utils@1Utilisation rapide
ts
import { D, DPE } from "@duplojs/utils";
import { Signer, createTokenHandler } from "@duplojs/json-web-token";
const tokenHandler = createTokenHandler({
maxAge: D.createTime(15, "minute"),
signer: Signer.createHS256({
secret: "my-secret",
}),
customPayloadShape: {
userId: DPE.string(),
},
});
const token = await tokenHandler.create({
userId: "1",
});
// send to client ...
const verifiedToken = await tokenHandler.verify("receive-token");