apps/gateway/src/utils/authorization.ts
Metadata
- Purpose: Source artifact in the anchor-msp system.
- Domain:
applications - Language:
ts - Bytes: 412
- Lines: 18
- Content hash (short):
23512df4 - Source (start): apps/gateway/src/utils/authorization.ts:1
- Source (end): apps/gateway/src/utils/authorization.ts:18
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;
}