From 348c97710fea49bd65b47820e98b82b08e9e320d Mon Sep 17 00:00:00 2001 From: Jin Mao Date: Mon, 3 Nov 2025 19:34:45 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"refactor(jwt):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20JWT=20=E5=B7=A5=E5=85=B7=E5=87=BD=E6=95=B0=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=20(#6869)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a854760d26ed06dbca1a00fd4593391aae7d2ef8. --- apps/backend-mock/utils/jwt-utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/backend-mock/utils/jwt-utils.ts b/apps/backend-mock/utils/jwt-utils.ts index f0f74323..71858307 100644 --- a/apps/backend-mock/utils/jwt-utils.ts +++ b/apps/backend-mock/utils/jwt-utils.ts @@ -3,7 +3,7 @@ import type { EventHandlerRequest, H3Event } from 'h3'; import type { UserInfo } from './mock-data'; import { getHeader } from 'h3'; -import { sign, verify } from 'jsonwebtoken'; +import jwt from 'jsonwebtoken'; import { MOCK_USERS } from './mock-data'; @@ -17,11 +17,11 @@ export interface UserPayload extends UserInfo { } export function generateAccessToken(user: UserInfo) { - return sign(user, ACCESS_TOKEN_SECRET, { expiresIn: '7d' }); + return jwt.sign(user, ACCESS_TOKEN_SECRET, { expiresIn: '7d' }); } export function generateRefreshToken(user: UserInfo) { - return sign(user, REFRESH_TOKEN_SECRET, { + return jwt.sign(user, REFRESH_TOKEN_SECRET, { expiresIn: '30d', }); } @@ -40,7 +40,7 @@ export function verifyAccessToken( } const token = tokenParts[1] as string; try { - const decoded = verify( + const decoded = jwt.verify( token, ACCESS_TOKEN_SECRET, ) as unknown as UserPayload; @@ -61,7 +61,7 @@ export function verifyRefreshToken( token: string, ): null | Omit { try { - const decoded = verify(token, REFRESH_TOKEN_SECRET) as UserPayload; + const decoded = jwt.verify(token, REFRESH_TOKEN_SECRET) as UserPayload; const username = decoded.username; const user = MOCK_USERS.find( (item) => item.username === username,