fix(build): remove oauth imports
not yet!
This commit is contained in:
parent
c04823a0e9
commit
f2e40dabf5
@ -1,26 +1,19 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import { log } from "@server/logger";
|
||||
import { User } from "@models/user";
|
||||
import { messages } from "@server/constants";
|
||||
import { AccessToken } from "@models/oauth";
|
||||
|
||||
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.JwtPayload;
|
||||
try {
|
||||
toktok = jwt.verify(ahead, useRuntimeConfig().jwt) as jwt.JwtPayload;
|
||||
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;
|
||||
} catch (e) {
|
||||
const t = await AccessToken.findOne({ token: ahead });
|
||||
if (!t)
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
message: messages[401],
|
||||
});
|
||||
let user = await User.findById(t.userID);
|
||||
if (user) event.context.currentUser = user;
|
||||
// else throw createError({statusCode: 401, message: messages[401]})
|
||||
}
|
||||
// setCookie(event, "auth:token", ahead)
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user