Skip to main content

apps/gateway/src/utils/authorization.ts

Metadata

Indexed Symbols

  • ensureRoles (line 3, function) - Implements ensure roles for module behavior.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import type { FastifyReply, FastifyRequest } from "fastify";

export function ensureRoles(request: FastifyRequest, reply: FastifyReply, allowedRoles: string[]): boolean {
const auth = request.auth;
if (!auth) {
reply.code(401);
return false;
}

const hasRole = auth.roles.some((role) => allowedRoles.includes(role));
if (!hasRole) {
reply.code(403);
return false;
}

return true;
}