Refactored permissions check. Updated redis lib.

This commit is contained in:
Mike Cao committed 2022-12-01 10:58:50 -08:00
1 parent 1a7369e1f6
commit a4e80ca3e5
5 files changed
+58 -15

No files matched your search

+20
View File
@@ -120,3 +120,23 @@ export async function checkPermission(req: NextApiRequestAuth, type: UmamiApi.Pe
return userRole.length > 0;
}
export async function canViewWebsite(userId: string, websiteId: string) {
const website = await cache.fetchWebsite(websiteId);
if (website.userId) {
return userId === website.userId;
}
return false;
}
export async function canUpdateWebsite(userId: string, websiteId: string) {
const website = await cache.fetchWebsite(websiteId);
if (website.userId) {
return userId === website.userId;
}
return false;
}