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.

827 B
Raw Blame
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { authClient } from "@/lib/auth-client";
import type {
  CreateApiKeyClientRequest,
  CreateApiKeyResponse,
} from "@/types/api-key";

function useCreateApiKey() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async (data: CreateApiKeyClientRequest) => {
      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;