18 lines
439 B
TypeScript
18 lines
439 B
TypeScript
import type { FastifyRequest, FastifyReply } from "fastify";
|
|
|
|
export const verifyUser = async (request: FastifyRequest, reply: FastifyReply) => {
|
|
try {
|
|
const { id } = await request.jwtVerify<{ id?: string }>();
|
|
|
|
if (!id) {
|
|
void reply.status(401);
|
|
return reply.send("user id is empty");
|
|
}
|
|
|
|
request.user = { id };
|
|
} catch (nativeError) {
|
|
void reply.status(401);
|
|
return reply.send(nativeError);
|
|
}
|
|
};
|