20 lines
606 B
TypeScript
20 lines
606 B
TypeScript
import jwt from "jsonwebtoken";
|
|
import { User } from "~/models/user";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
let ahead = (getHeaders(event).authorization || "")?.replace("Bearer ", "");
|
|
console.log(`=------------------------${event.path}`);
|
|
console.log("h", getHeaders(event));
|
|
console.log(JSON.stringify(ahead));
|
|
if (ahead) {
|
|
console.log("ahead", ahead);
|
|
let toktok = jwt.verify(
|
|
ahead,
|
|
// ahead.replace("Bearer ", ""),
|
|
useRuntimeConfig().jwt,
|
|
) as jwt.JwtPayload;
|
|
let user = await User.findById(toktok.id as number).exec();
|
|
event.context.currentUser = user;
|
|
}
|
|
});
|