feat: initial impl of file proxy

This commit is contained in:
2025-10-21 23:45:04 +00:00
parent 6eded27121
commit 6234c5efd3
24 changed files with 420 additions and 125 deletions

View File

@@ -26,6 +26,10 @@ export type AuthenticatedMutationCtx = MutationCtx & {
identity: UserIdentity
}
export type ApiKeyAuthenticatedQueryCtx = QueryCtx & {
__branded: "ApiKeyAuthenticatedQueryCtx"
}
/**
* Custom query that automatically provides authenticated user context
* Throws an error if the user is not authenticated
@@ -52,6 +56,21 @@ export const authenticatedMutation = customMutation(
}),
)
/**
* Custom query that requires api key authentication for a query.
*/
export const apiKeyAuthenticatedQuery = customQuery(query, {
args: {
apiKey: v.string(),
},
input: async (ctx, args) => {
if (!(await ApiKey.verifyApiKey(ctx, args.apiKey))) {
throw Err.create(Err.Code.Unauthenticated, "Invalid API key")
}
return { ctx: ctx as ApiKeyAuthenticatedQueryCtx, args }
},
})
/**
* Custom mutation that requires api key authentication for a mutation.
*/