chore: add authorization to server actions for Actions (#868)

* 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 action creation, update, delete

* feat: use cached method across and wrapper for authzn check

* fix: club caching methods and use authzn errors

* feat: add caching in canUserAccessApiKey

* feat: add caching in canUserAccessAction and use Authzn error

* fix: rename action to actionClass wherever needed

* fix: use cache getActionClass

* fix: make changes

* fix: import

---------

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Shubham Palriwala
2023-10-02 16:33:49 +05:30
committed by GitHub
parent e01d5a44f4
commit c4b4d2a312
14 changed files with 179 additions and 116 deletions
+2 -3
View File
@@ -2,8 +2,8 @@ import { hasUserEnvironmentAccess } from "../environment/auth";
import { getApiKey } from "./service";
import { unstable_cache } from "next/cache";
export const canUserAccessApiKey = async (userId: string, apiKeyId: string): Promise<boolean> => {
return await unstable_cache(
export const canUserAccessApiKey = async (userId: string, apiKeyId: string): Promise<boolean> =>
await unstable_cache(
async () => {
if (!userId) return false;
@@ -19,4 +19,3 @@ export const canUserAccessApiKey = async (userId: string, apiKeyId: string): Pro
[`users-${userId}-apiKeys-${apiKeyId}`],
{ revalidate: 30 * 60, tags: [`apiKeys-${apiKeyId}`] }
)(); // 30 minutes
};