Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(web): add create api key mutation hook

Andrej Acevskib1ba33df43da
diff --git a/apps/web/src/hooks/mutations/api-key/use-create-api-key.ts b/apps/web/src/hooks/mutations/api-key/use-create-api-key.ts
new file mode 100644
index 000000000..6f136e276
--- /dev/null
+++ b/apps/web/src/hooks/mutations/api-key/use-create-api-key.ts
@@ -0,0 +1,32 @@
+import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { authClient } from "@/lib/auth-client";
+import type {
+ CreateApiKeyRequest,
+ CreateApiKeyResponse,
+} from "@/types/api-key";
+
+function useCreateApiKey() {
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn: async (data: CreateApiKeyRequest) => {
+ const result = await authClient.apiKey.create({
+ name: data.name,
+ expiresIn: data.expiresIn,
+ prefix: data.prefix,
+ metadata: data.metadata,
+ });
+
+ if (result.error) {
+ throw new Error(result.error.message);
+ }
+
+ return result.data as CreateApiKeyResponse;
+ },
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ["api-keys"] });
+ },
+ });
+}
+
+export default useCreateApiKey;