mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 03:28:43 +00:00
22 lines
915 B
TypeScript
22 lines
915 B
TypeScript
import fp from "fastify-plugin";
|
|
|
|
import { ActorType } from "@app/services/auth/auth-type";
|
|
|
|
// inject permission type needed based on auth extracted
|
|
export const injectPermission = fp(async (server) => {
|
|
server.decorateRequest("permission", null);
|
|
server.addHook("onRequest", async (req) => {
|
|
if (!req.auth) return;
|
|
|
|
if (req.auth.actor === ActorType.USER) {
|
|
req.permission = { type: ActorType.USER, id: req.auth.userId, orgId: req.auth?.orgId };
|
|
} else if (req.auth.actor === ActorType.IDENTITY) {
|
|
req.permission = { type: ActorType.IDENTITY, id: req.auth.identityId };
|
|
} else if (req.auth.actor === ActorType.SERVICE) {
|
|
req.permission = { type: ActorType.SERVICE, id: req.auth.serviceTokenId };
|
|
} else if (req.auth.actor === ActorType.SCIM_CLIENT) {
|
|
req.permission = { type: ActorType.SCIM_CLIENT, id: req.auth.scimTokenId, orgId: req.auth.orgId };
|
|
}
|
|
});
|
|
});
|