Files
webstudio/apps/builder/app/services/builder-access.server.ts

23 lines
720 B
TypeScript

import { authorizeProject } from "@webstudio-is/trpc-interface/index.server";
import { createPostgrestContext } from "~/shared/context.server";
/**
* Check if a user is authorized to access a project during the Builder authentication process.
*/
export const isUserAuthorizedForProject = async (
userId: string,
projectId: string
) => {
const postgrestContext = createPostgrestContext();
// Only the project owner can access the Builder URL with authentication credentials (session).
const isProjectOwner = await authorizeProject.checkProjectPermit({
projectId,
permit: "own",
authInfo: { type: "user", userId },
postgrestClient: postgrestContext.client,
});
return isProjectOwner;
};