Skip to main content

useApiAuthKeys

The useApiAuthKeys hook manages API auth keys for the current API auth app session.

Parameters

filters.status
string
Optional key status filter.

Return Value

keys
ApiKey[]
Current key list.
loading
boolean
Whether keys are loading.
error
unknown
Error from the latest request.
createKey
(input: CreateApiAuthKeyInput) => Promise<ApiKeyWithSecret>
Create a new key and receive its secret once.
rotateKey
(input: RotateApiAuthKeyInput) => Promise<ApiKeyWithSecret>
Rotate an existing key and receive the new secret.
revokeKey
(input: RevokeApiAuthKeyInput) => Promise<void>
Revoke a key.
refetch
() => void
Revalidate key list.

Example

import { useApiAuthKeys } from "@wacht/react-router";

function KeysTable() {
  const { keys, createKey, revokeKey } = useApiAuthKeys({ status: "active" });

  return (
    <div>
      <button onClick={() => void createKey({ name: "CI key" })}>Create key</button>
      <ul>
        {keys.map((key) => (
          <li key={key.id}>
            {key.name}
            <button onClick={() => void revokeKey({ key_id: key.id })}>Revoke</button>
          </li>
        ))}
      </ul>
    </div>
  );
}