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

@@ -6,13 +6,7 @@ import { userSchemas } from "./user/user.schema";
import { orgSchemas } from "./organization/organization.schema";
import { tokenSchemas } from "./tokens/token.schema";
import { errorHandler } from "./utils/errors";
import { AuthenticatedUser, authHandler } from "./auth";
declare module "fastify" {
export interface FastifyRequest {
user: AuthenticatedUser;
}
}
import { authHandler, authorize } from "./auth";
const app = fastify({ logger: true });
@@ -20,9 +14,10 @@ app.get("/health", (req, res) => {
return { status: "OK" };
});
app.register(routes, { prefix: "/api/v1" });
app.decorate("authorize", authorize);
app.setErrorHandler(errorHandler);
app.addHook("onRequest", authHandler);
app.register(routes, { prefix: "/api/v1" });
for (const schema of [...userSchemas, ...orgSchemas, ...tokenSchemas]) {
app.addSchema(schema);