Authentication
Lark supports anonymous and token-based authentication. You choose how to authenticate when you connect, and you can change authentication state after connecting.Anonymous authentication
The simplest option. Connect without any user identity:Token-based authentication
For identified users, pass a JWT at connect time:auth.uid, auth.provider, and any custom claims.
Changing auth state after connecting
You don’t have to authenticate at connect time. You can sign in or out at any point after connecting.db.signIn(token)
Authenticate with a new token. If you were previously anonymous or signed in as a different user, the auth state updates:
db.signOut()
Reverts to anonymous authentication:
After calling
signOut(), the connection stays open. You’re still connected, just without user identity. Any subscriptions that depend on authenticated access (via security rules) may stop receiving updates.The auth property
Access the current authentication state at any time:
| Property | Type | Description |
|---|---|---|
uid | string | The user’s unique identifier. |
provider | string | The authentication provider (e.g., "custom", "google"). |
token | string | The raw JWT. |
Listening for auth changes
Usedb.onAuthStateChanged(callback) to react to sign-in and sign-out events:

