From f0058ae87bfdb915cd89d120b879c21f1681b0d1 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 2 Jan 2025 12:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0index.d.ts=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 27 +++++++++++++++++++++++++++ index.js | 2 +- package.json | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..f1eefe4 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,27 @@ +import Request from '@gm5/request' +import Response from '@gm5/response' + +declare module '@gm5/jwt' { + interface JwtConfig { + ttl?: number + level?: number + secret: string + } + + interface JwtModule { + name: string + install(conf?: JwtConfig): { + ttl: number + sign(data: object, secret: string): string + verify(token: string, secret: string): object | false + } + } + + export const JwtModule: JwtModule + + export function createJwt(): ( + req: Request, + res: Response, + next: () => void + ) => void +} diff --git a/index.js b/index.js index eae5e82..d204795 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ export const JwtModule = { if (!conf.secret) { console.warn( new Error( - 'Please make sure to set the `secret` field, as the default value is not secure' + 'You must set a `secret` key for jwt, or it will use the default key.' ) ) } diff --git a/package.json b/package.json index f941084..1b5d6fe 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "@gm5/jwt", - "version": "2.0.2", + "version": "2.0.3", "type": "module", "description": "json web token", "main": "index.js", + "types": "index.d.ts", "author": "yutent", "keywords": [ "fivejs",