Add authorization
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user