20 lines
505 B
TypeScript
20 lines
505 B
TypeScript
![]() |
import type { FastifyRequest, FastifyReply, HookHandlerDoneFunction as Done } from "fastify";
|
||
|
|
||
|
export const verifyUser = async (request: FastifyRequest, reply: FastifyReply, done: Done) => {
|
||
|
try {
|
||
|
const { id } = await request.jwtVerify<{ id?: string }>({ onlyCookie: true });
|
||
|
|
||
|
if (!id) {
|
||
|
reply.status(401);
|
||
|
return reply.send("user id is empty");
|
||
|
}
|
||
|
|
||
|
request.user = { id };
|
||
|
} catch (nativeError) {
|
||
|
reply.status(401);
|
||
|
return reply.send(nativeError);
|
||
|
}
|
||
|
|
||
|
done();
|
||
|
};
|