feat(server/middleware): add the h3 equivalent of req.user to incoming request contexts

This commit is contained in:
parent 740d8a9f2c
commit f0a006b3d5
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

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