Revert "refactor(jwt): 更新 JWT 工具函数实现方式 (#6869)"

This reverts commit a854760d26.
This commit is contained in:
Jin Mao 2025-11-03 19:34:45 +08:00
parent a854760d26
commit 348c97710f

View File

@ -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<UserInfo, 'password'> {
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,