feat:版本迭代

This commit is contained in:
jiangrui
2025-02-20 12:00:19 +08:00
parent fd110590af
commit 510fdc48f6
86 changed files with 5045 additions and 1161 deletions

View File

@@ -0,0 +1,21 @@
import jwt from "jsonwebtoken";
import { Request } from "express";
import { config } from "../config";
interface JwtPayload {
userId: string;
}
export function getUserIdFromToken(req: Request): string | null {
try {
const token = req.headers.authorization?.split(" ")[1];
if (!token) {
throw new Error("Token not found");
}
const decoded = jwt.verify(token, config.jwtSecret) as JwtPayload;
return decoded.userId;
} catch (error) {
console.error("Invalid token:", error);
return null;
}
}