2023-06-22 13:29:48 +00:00
|
|
|
import type { FastifyRequest, FastifyReply } from "fastify";
|
2022-12-20 15:07:06 +00:00
|
|
|
|
2023-06-22 13:29:48 +00:00
|
|
|
export const verifyUser = async (request: FastifyRequest, reply: FastifyReply) => {
|
2022-12-20 15:07:06 +00:00
|
|
|
try {
|
2022-12-22 10:45:44 +00:00
|
|
|
const { id } = await request.jwtVerify<{ id?: string }>();
|
2022-12-20 15:07:06 +00:00
|
|
|
|
|
|
|
if (!id) {
|
2023-06-01 22:07:43 +00:00
|
|
|
void reply.status(401);
|
2022-12-20 15:07:06 +00:00
|
|
|
return reply.send("user id is empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
request.user = { id };
|
|
|
|
} catch (nativeError) {
|
2023-06-01 22:07:43 +00:00
|
|
|
void reply.status(401);
|
2022-12-20 15:07:06 +00:00
|
|
|
return reply.send(nativeError);
|
|
|
|
}
|
|
|
|
};
|