mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 03:21:20 -05:00
8c0aba82e5
* poc: use server session and api key validation on deletion * feat: use server session and api key validation on deletion and creation * feat: packages/lib/apiKey for apiKey services and auth * shubham/auth-for-api-key * fix: caching * feat: handle authorization for tag creation, updation & deletion * fix: use cached wrapper * fix: club caching methods and use authzn errors * feat: add caching in canUserAccessApiKey * fix: suggrsted changes and authzn for response as well * fix: work on suggested changes * fix broken lock file --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { prisma } from "@formbricks/database";
|
|
import { ZId } from "@formbricks/types/v1/environment";
|
|
import { unstable_cache } from "next/cache";
|
|
import { validateInputs } from "../utils/validate";
|
|
|
|
export const hasUserEnvironmentAccess = async (userId: string, environmentId: string) => {
|
|
return await unstable_cache(
|
|
async () => {
|
|
validateInputs([userId, ZId], [environmentId, ZId]);
|
|
const environment = await prisma.environment.findUnique({
|
|
where: {
|
|
id: environmentId,
|
|
},
|
|
select: {
|
|
product: {
|
|
select: {
|
|
team: {
|
|
select: {
|
|
memberships: {
|
|
select: {
|
|
userId: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
const environmentUsers = environment?.product.team.memberships.map((member) => member.userId) || [];
|
|
return environmentUsers.includes(userId);
|
|
},
|
|
[`users-${userId}-environments-${environmentId}`],
|
|
{ revalidate: 30 * 60, tags: [`environments-${environmentId}`] }
|
|
)(); // 30 minutes
|
|
};
|