feat: create and delete api keys

This commit is contained in:
Henry
2025-05-31 23:59:48 +01:00
parent e61dd4e27e
commit 1d00aa78b4
11 changed files with 153 additions and 24 deletions

View File

@@ -0,0 +1,60 @@
import { authClient } from "@kan/auth";
import Button from "~/components/Button";
import Input from "~/components/Input";
const CreateAPIKeyForm = ({
apiKey,
refetchUser,
}: {
apiKey:
| {
id: number;
prefix: string | null;
key: string;
}
| null
| undefined;
refetchUser: () => void;
}) => {
console.log({ apiKey });
const handleCreateAPIKey = async () => {
await authClient.apiKey.create();
refetchUser();
};
const handleRevokeAPIKey = async () => {
if (!apiKey) return;
await authClient.apiKey.delete({
keyId: apiKey.id.toString(),
});
refetchUser();
};
return (
<div>
{apiKey ? (
<div className="flex gap-2">
<div className="mb-4 flex w-full max-w-[325px] items-center gap-2">
<Input
value={`${apiKey.prefix}${apiKey.key}`}
readOnly
type="password"
/>
</div>
<div>
<Button variant="danger" onClick={handleRevokeAPIKey}>
Revoke
</Button>
</div>
</div>
) : (
<Button onClick={handleCreateAPIKey}>Create new key</Button>
)}
</div>
);
};
export default CreateAPIKeyForm;