Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

732 B
Raw Blame
import { PrincipalType } from '@activepieces/shared'
import { FastifyRequest } from 'fastify'
import { platformService } from '../platform/platform.service'

export const securityHelper = {
    async getUserIdFromRequest(request: FastifyRequest): Promise<string | null> {
        switch (request.principal.type) {
            case PrincipalType.SERVICE: {
                const platform = await platformService(request.log).getOneOrThrow(request.principal.platform.id)
                return platform.ownerId
            }
            case PrincipalType.USER:
                return request.principal.id
            default:
                throw new Error(`Unsupported principal type: ${request.principal.type}`)
        }
    },
}