The Kotlin SDK supports the full range of SurrealDB authentication methods: root, namespace, and database users, as well as record (scoped) access. Credentials are supplied as a JsonObject, built with buildJsonObject.
API references
| Method | Description |
|---|---|
client.signup(params) | Signs up against a record access method |
client.signin(params) | Signs in with credentials |
client.authenticate(token) | Authenticates with an existing token |
client.auth() | Returns the current authentication record |
client.invalidate() | Invalidates the current session authentication |
client.reset() | Resets the session to an unauthenticated state |
Signing in
Use .signin() with the credentials appropriate to the level of access you need. It returns the authentication token as a JsonElement.
Signing up
Use .signup() to register against a record access method.
Authenticating with a token
If you already hold a token (for example from a previous session), authenticate the connection with .authenticate().
Inspecting and clearing authentication
Retrieve the currently authenticated record with .auth(), drop the authentication while keeping the connection open with .invalidate(), or fully reset the session state with .reset().
Automatic authentication and token renewal
The client can authenticate automatically on connect and after reconnects, and renew tokens shortly before they expire. Provide a credentialProvider and enable autoAuthenticate on your SurrealClientConfig. The provider returns a SurrealAuthInput — either a SignIn with credentials or an existing Token.
Learn more
SurrealClient API reference for complete method signatures
Client configuration for
credentialProviderand renewal optionsMultiple sessions for per-session authentication
SurrealDB authentication for an overview of authentication concepts