Authentication
@kalamdb/client models auth as a tagged union with type-safe constructors.
The same Auth and authProvider model is reused by createConsumerClient() in @kalamdb/consumer.
Auth modes
authProvider — the only auth option
All clients must provide an authProvider callback. The client resolves it
during initialization, and the WASM transport uses it again for WebSocket
connect/reconnect auth resolution, so token refresh stays centralized in one
place.
With user/password bootstrap
Return Auth.basic(user, pass) when your app starts from user/password
credentials. The SDK only uses those credentials on POST /v1/api/auth/login
and exchanges them for a JWT before the first authenticated query or WebSocket
connection:
With OAuth / SSO
Fetch and return a fresh JWT from your token endpoint:
User/password → JWT login upgrade
login() exchanges user/password credentials for a JWT. When the client was created
with authProvider returning Auth.basic(...), the SDK calls this
automatically before the first query or WebSocket connection. You can also call
it manually:
Refresh token
refreshToken() updates the internal auth to the new JWT token.
Auth helpers
buildAuthHeader() returns:
- basic → throws, because user/password credentials are only valid for
POST /v1/api/auth/login - jwt →
Bearer <token>
For basic, buildAuthHeader() throws because user/password credentials are
only valid for POST /v1/api/auth/login.
Used internally by queryWithFiles() after the login exchange has produced JWT auth.