mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-04 19:39:39 -05:00
28 lines
938 B
TypeScript
28 lines
938 B
TypeScript
"use server";
|
|
|
|
import "server-only";
|
|
import { AuthorizationError, ResourceNotFoundError } from "@formbricks/types/errors";
|
|
import { getOrganizationByEnvironmentId } from "../../organization/service";
|
|
import { getMembershipByUserIdOrganizationId } from "../service";
|
|
|
|
export const getMembershipByUserIdOrganizationIdAction = async (environmentId: string, userId: string) => {
|
|
const organization = await getOrganizationByEnvironmentId(environmentId);
|
|
|
|
if (!organization) {
|
|
throw new ResourceNotFoundError("Organization", null);
|
|
}
|
|
|
|
const currentUserMembership = await getMembershipRole(userId, organization.id);
|
|
|
|
return currentUserMembership;
|
|
};
|
|
|
|
export const getMembershipRole = async (userId: string, organizationId: string) => {
|
|
const membership = await getMembershipByUserIdOrganizationId(userId, organizationId);
|
|
if (!membership) {
|
|
throw new AuthorizationError("Not authorized");
|
|
}
|
|
|
|
return membership.role;
|
|
};
|