next/server/api/auth/session.get.ts

18 lines
427 B
TypeScript
Raw Normal View History

import jwt from "jsonwebtoken";
import { log } from "~/lib/server/logger";
export default eventHandler((event) => {
let ahead = (
getHeaders(event).authorization ||
getCookie(event, "auth:token") ||
""
)?.replace("Bearer ", "");
if (event.context.currentUser) {
return {
token: ahead,
user: event.context.currentUser,
};
} else {
throw createError({ statusCode: 400, message: "unauthenticated" });
}
});