Add authorization

This commit is contained in:
2024-12-20 13:17:53 +05:30
parent 4b49c43a0c
commit a584fc91b5
16 changed files with 112 additions and 58 deletions

View File

@@ -3,24 +3,22 @@ import { CreateTokenInput } from "./token.schema";
import { createToken, getToken } from "./token.service";
export async function createTokenHandler(
req: FastifyRequest<{ Body: CreateTokenInput }>,
req: FastifyRequest,
res: FastifyReply
) {
const input = req.body;
const input = req.body as CreateTokenInput;
try {
const result = await createToken(input);
const authUser = req.user;
const result = await createToken(input, authUser.tenantId);
return res.code(201).send(result);
} catch (err) {
return err;
}
}
export async function getTokenHandler(
req: FastifyRequest<{ Params: { tokenId: string } }>,
res: FastifyReply
) {
const { tokenId } = req.params;
export async function getTokenHandler(req: FastifyRequest, res: FastifyReply) {
const { tokenId } = req.params as { tokenId: string };
try {
const token = await getToken(tokenId);