refactor(server/middleware): rename currentUser middleware

This commit is contained in:
parent 6afc547f8e
commit d67530eb64
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 23 additions and 15 deletions

@ -0,0 +1,23 @@
import jwt from "jsonwebtoken";
import { log } from "~/lib/server/logger";
import { User } from "~/models/user";
export default defineEventHandler(async (event) => {
let ahead = (
getHeaders(event).authorization ||
getCookie(event, "auth:token") ||
""
)?.replace("Bearer ", "");
// console.log("in here fucknuts", ahead);
// log.debug(`'${ahead}'`, { label: "idk" });
if (ahead) {
let toktok = jwt.verify(
ahead,
// ahead.replace("Bearer ", ""),
useRuntimeConfig().jwt,
) as jwt.JwtPayload;
let user = await User.findById(toktok.id as number).exec();
if (user && toktok) event.context.currentUser = user;
// setCookie(event, "auth:token", ahead)
}
});

@ -1,15 +0,0 @@
import jwt from "jsonwebtoken";
import { User } from "~/models/user";
export default defineEventHandler(async (event) => {
let ahead = (getHeaders(event).authorization || "")?.replace("Bearer ", "");
if (ahead) {
let toktok = jwt.verify(
ahead,
// ahead.replace("Bearer ", ""),
useRuntimeConfig().jwt,
) as jwt.JwtPayload;
let user = await User.findById(toktok.id as number).exec();
if (user) event.context.currentUser = user;
}
});