feat(server/middleware): add the h3 equivalent of req.user
to incoming request contexts
This commit is contained in:
parent
740d8a9f2c
commit
f0a006b3d5
12
server/middleware/currentUser.ts
Normal file
12
server/middleware/currentUser.ts
Normal file
@ -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
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user