2023-10-10 22:27:47 -04:00
|
|
|
import jwt from "jsonwebtoken";
|
|
|
|
import { log } from "~/lib/server/logger";
|
2023-09-28 21:55:19 -04:00
|
|
|
export default eventHandler((event) => {
|
2023-10-10 22:27:47 -04:00
|
|
|
let ahead = (
|
|
|
|
getHeaders(event).authorization ||
|
|
|
|
getCookie(event, "auth:token") ||
|
|
|
|
""
|
|
|
|
)?.replace("Bearer ", "");
|
2023-09-28 21:55:19 -04:00
|
|
|
if (event.context.currentUser) {
|
|
|
|
return {
|
2023-10-10 22:27:47 -04:00
|
|
|
token: ahead,
|
2023-09-28 21:55:19 -04:00
|
|
|
user: event.context.currentUser,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
throw createError({ statusCode: 400, message: "unauthenticated" });
|
|
|
|
}
|
|
|
|
});
|