Skip to content

Let strangers sign in to your app (end users)

Let people sign in to your public app with an email code, a social account or as a guest. They don't need a Kovlet account. Kovlet calls them end users.

8 min readUpdated December 2026Markdown
On this page

At a glance

  • Each Data Space has its own list of end users, separate from Kovlet accounts, members, seats and machines.
  • An owner turns end-user sign-in on per app. The app must be approved, with pinned origins or redirect URIs.
  • End users can't read a table until the space's rulesPer-record permissions for end users, written in CEL per table and action. Closed by default. allow it.
  • The system table _users lists them. Your tables point at a user with t.ref("_users").
  • Server code can act as an end user. Every REST route is in the end users REST API reference.

End users can sign in with:

  • an email code
  • Google, Apple, GitHub or LinkedIn
  • an identity provider you already run: Clerk, Firebase, Auth0 or any OIDC issuer
  • a guest account

End users are closed by default. They can't read a table until the space's rules allow it.

Server code with a Machine Auth KeyA key (kvm_…) created in the console for an unattended server, exchanged for a session token. can act as an end user, with the Kovlet-As-End-User header. An owner must first set the impersonate flag on its machine grant.

Prerequisites

  • A Data Space you own, and an app connected to it, for example from the web quickstart. The app must be approved. It also needs a pinned origin (web) or redirect URI (native).
  • The app's ID and the Data Space's ID. Both are public identifiers, not secrets.
  • @kovlet/client (and @kovlet/react for the React sample), or one of the native SDKs.

Step 1: Turn on end-user sign-in

You do this once, as an owner, in the console. Open Access for the Data Space, then the End users tab.

  1. Apps. Switch on *End-user sign-in* for the app. The app must be approved. It needs at least one pinned origin (web) or redirect URI (native). The console lists anything that's missing.
  2. Sign-in methods. Email codes work as soon as sign-in is on. For the other methods:
    • Google, Apple, GitHub or LinkedIn: create an OAuth client in that provider's console. Your app's name and logo show on its consent screen, not Kovlet's. Register Kovlet's callback URL, shown on the page. Then paste the client ID and secret.
    • Clerk, Firebase, Auth0 or another OIDC issuer: enter its issuer URL and audience.
  3. Rules. Choose which tables end users may view, create, update and delete. Tick whole tables, or write per-row rules such as auth.id == data.owner in *Code*.
    • Until a rule allows it, every action is denied.
    • _users defaults to "each end user sees their own row".
    • *Test as an end user* shows what one end user gets before you save.

Rules are CEL expressions, as in InstantDB. See Write per-record rules for end users.

Step 2: Sign in from the app

In kovlet.ts, pass the app's ID as appId. Pin the one Data Space whose end users it signs in with spaceId.

kovlet.ts
import { createKovletClient, t } from "@kovlet/client";

export const kovlet = createKovletClient({
  appName: "Public Board",
  appId: "app_…",
  spaces: { board: { spaceId: "spc_…", tables: { todos: { owner: t.ref("_users"), title: t.string() } } } },
});

Then call the sign-in method you want from kovlet.auth:

sign-in.ts
import { kovlet } from "./kovlet";

// Email code
export async function signInWithEmail(email: string, code?: string) {
  if (!code) return kovlet.auth.sendMagicCode({ email }); // { expiresIn }
  const { user } = await kovlet.auth.signInWithMagicCode({ email, code });
  return user;
}

// Guest, upgraded later by any other method
export const signInAsGuest = () => kovlet.auth.signInAsGuest();

// OAuth: redirects to the provider, then back to redirectUri
export const signInWithGoogle = () =>
  kovlet.auth.signInWithOAuth({ provider: "google", redirectUri: `${location.origin}/auth/callback` });
// On the callback page: resolves null when the URL is not an OAuth return
export const finishSignIn = () => kovlet.auth.completeOAuth();

// An ID token from Clerk, Firebase, Auth0 or any OIDC issuer you configured
export const signInWithClerk = (idToken: string) => kovlet.auth.signInWithIdToken({ provider: "clerk", idToken });

kovlet.auth.user; // { id, email, emailVerified, isGuest, createdAt } | null
const off = kovlet.auth.onChange((user) => console.log(user?.id ?? "signed out"));
export const signOut = () => kovlet.auth.signOut();
  • Every sign-in resolves { user, guestId? }. guestId is set when a guest signed in with an identity that already belonged to another end user.
  • kovlet.auth.signInWithSignInCode({ code }) redeems a code your server minted. See Admin access.
  • kovlet.auth.getConfig() returns { enabled, providers }. Use it to show only the methods the owner configured.
  • Outside browsers, open await kovlet.auth.oauthUrl({ provider, redirectUri }) yourself. Then pass the return URL to kovlet.auth.completeOAuth(url). A return whose state this tab didn't start rejects with state_mismatch.
  • Errors: RateLimitedError (retryAfter seconds), and KovletHttpError with quota_exceeded, end_users_disabled, forbidden or invalid_grant.

With appId, the client doesn't open Kovlet's consent screen on its own. Member sign-in (kovlet.connect()) is for people with a Kovlet account.

Tokens are kept per space and app in the client's storage. They are bound to its device key and refreshed automatically.

In React, useAuth() returns { user, isLoading, error } and re-renders on sign-in and sign-out. @kovlet/vue and @kovlet/svelte have the same useAuth(), as a ref and a store.

Note Both IDs in the config are public identifiers, not secrets. So onboarding stays zero-key.

Native apps (Swift, Kotlin, Rust and Tauri)

The native SDKs have the same methods, on an end-user handle for one space and app:

Swift
let auth = kovlet.endUsers(spaceId: "spc_…", appId: "app_…")
try await auth.sendMagicCode(to: email)
let signedIn = try await auth.signIn(email: email, code: code)   // or signInAsGuest(), signIn(idToken:provider:), signIn(signInCode:)
Kotlin
val auth = kovlet.endUsers("spc_…", appId = "app_…")
auth.sendMagicCode(email)
val signedIn = auth.signInWithMagicCode(email, code)               // or signInAsGuest(), signInWithIdToken(...), signInWithOAuth(activity, ...)
Rust
let auth = kovlet.end_users("spc_…", "app_…");
auth.send_magic_code(&email).await?;
let signed_in = auth.sign_in_with_magic_code(&email, &code).await?;   // or sign_in_as_guest(), oauth_begin()/oauth_finish()
  • OAuth opens the provider in ASWebAuthenticationSession (Swift), a Custom Tab (Kotlin) or the system browser (Rust and Tauri).
  • Register a reverse-DNS redirect URI such as com.example.todos:/oauth for the app. Desktop apps can also use a loopback http://127.0.0.1 redirect.
  • The session is bound to the SDK's device key, kept in the platform's secure storage, and refreshed automatically.
  • While an end user is signed in, every space the client opens syncs over protocol 2 with query subscriptions (space.subscribe(...)). The rows are filtered by the space's rules.
  • Signing out forgets the synced rows and queued writes on the device.
  • A Tauri webview signs in through the plugin's end_user_* commands.

The platform quickstarts show the whole flow: iOS, Android and Rust and Tauri.

Step 3: Read data as an end user

While an end user is signed in, the client syncs the pinned space as them. It uses protocol 2 (protocol §17.9).

useQuery, liveQuery and useTable are live queries for that end user. They hold only the rows the space's rules let them view. Rows move in and out as data, memberships or rules change.

Todos.tsx
import { useAuth, useQuery, useSpace } from "@kovlet/react";
import { kovlet } from "./kovlet";

export function Todos() {
  const { user } = useAuth();
  const board = useSpace<typeof kovlet>("board");
  const { data, isLoading } = useQuery(board, { todos: { $: { order: { title: "asc" } } } });
  if (!user) return <button onClick={() => kovlet.auth.signInAsGuest()}>Continue as guest</button>;
  if (isLoading) return <p>Loading…</p>;
  const add = (title: string) => board.table("todos").insert({ owner: user.id, title });
  return (
    <>
      <button onClick={() => add("New todo")}>Add</button>
      <ul>{data?.todos?.map((t) => <li key={t.id}>{t.title}</li>)}</ul>
    </>
  );
}

Writes go through the same socket. board.table("todos").insert({ owner: user.id, title }) shows at once and queues while offline. The server checks it against the rules when it arrives. A write the rules deny is rolled back. onError gets a MutationRejectedError with code: "forbidden" and details.rule (e.g. "todos.create").

How sign-in and sign-out affect sync:

  • Sign-in (magic code, OAuth, ID token, sign-in code or guest) connects as the end user. A stored session reconnects on the next load. autoConnect stays false: Kovlet's consent screen never opens for end users.
  • Token refresh keeps the socket and every subscription.
  • Sign-out, or signing in as someone else, closes the socket. It clears the previous end user's rows from the device. Their unsent writes stay queued for their next sign-in, and are never sent as anyone else.
  • Every open tab follows. Sign out, or in as someone else, in one tab of the app. Its other tabs on that origin do the same within a second: their live queries empty, their sockets close, and the previous end user's rows are cleared before anything syncs as the next one.
    • Tabs hear of it over a BroadcastChannel (a storage event where there is none), per app.
    • Other apps on the origin aren't touched, and neither is a tab's Kovlet-account session.
  • End users always use query subscriptions. The SDK never asks for the whole space ("*"). It never sends the slot's tables to the server, since the schema is the owner's. Declare tables anyway: they type useQuery and writes, and a t.ref("_users") column keeps its link to _users.
  • @kovlet/vue, @kovlet/svelte and @kovlet/react-native work the same through their useAuth() and useQuery(). kovlet.connect() reconnects as the end user, for example after the app comes back from the background.

For one-shot reads over REST, use kovlet.auth.records():

read.ts
import { kovlet } from "./kovlet";

// GET /v1/spaces/{space}/records?table=todos, with the end user's token
const todos = await kovlet.auth.records("todos");
const some = await kovlet.auth.records("todos", { ids: ["t1", "t2"] });

Each row is its fields plus id. Rows a rule doesn't allow never leave the server. A table without a view rule answers 403 forbidden with details.rule: "todos.view". A live query gets the same error in its error.

Save the owner rules from the rules how-to, then run the app.

You should see

  • Signed out, the Todos component shows only the *Continue as guest* button.
  • After you press it, the *Add* button and an empty list. The guest owns no to-dos yet.
  • *Add* puts "New todo" in the list at once. In a second browser profile, a different guest sees an empty list. The rules keep each end user's rows to themselves.

How end users fit the access model

Session and Who and Ceiling and Rules apply
SessionWhoCeilingRules apply
Member app (User, Machine, App)a Kovlet account on a devicemin(role(U,S), role(A,S))no
Headless (Machine, App)a Machine Auth Keyits machine grantno
Headless acting as an end usera Machine Auth Key plus Kovlet-As-End-Userits machine grantyes, as that end user
End user (EndUser, App)an end-user session (kvu_ token)the app's grant on the spaceyes
  • An end-user session is valid for exactly one Data Space. Any other space answers 403 forbidden.
  • End-user devices are not Kovlet machines: there is no machine row, no device quota, and require_approved_machines doesn't apply.
  • Revoking the app, turning sign-in off for it, or blocking the end user ends their sessions.

Admin access and impersonation

Server code signs in with a Machine Auth Key as usual. By default it isn't bound by rules. To act as an end user:

  • an owner sets Act as end users on the machine grant (console → Access → Machines → the machine's *Act as end users* switch);
  • the request carries Kovlet-As-End-User: <end user id> or Kovlet-As-End-User: email:<address>.

The request is then evaluated exactly as that end user, capped by the machine grant.

A server-side @kovlet/client syncs live as an end user with createKovletClient({ auth: { type: "machine-key", machineKey, clientId }, asEndUser: "<end user id>", … }). Its queries are filtered by the rules exactly as theirs are. Ops record the machine, the app and the end user. The activity feed labels them as impersonation.

For a custom auth backend (InstantDB's auth.createToken), the server mints a one-time sign-in code and hands it to its client. The client redeems it with grant_type=sign_in_code.

REST API

The SDKs call the end-user routes for you. To call them yourself, or to manage the directory from a server, see the Kovlet end users REST API reference. It covers sign-in and token grants, the data routes an end-user session may call, the directory, and the owner's settings.

Erasure, exports and retention

  • Block revokes the end user's sessions and refuses sign-in.
  • Delete removes the directory row, identities, sessions and the _users row. The _users row is hard-deleted, not trashed, and its oplog images are scrubbed.
  • Rows the end user wrote belong to the app. Find them in the activity feed with end_user=. Undo them with the rollback selector undo_end_user.
  • Exports of a space include its end-user directory.
  • Idle guests that were never upgraded are deleted after 30 days without activity.

InstantDB mapping

InstantDB and Kovlet
InstantDBKovlet
$users_users (system table; t.ref("_users") links to it)
db.auth.sendMagicCode / signInWithMagicCodekovlet.auth.sendMagicCode / signInWithMagicCode
Google / Apple / GitHub / LinkedIn OAuththe same providers, with your own OAuth client
Clerk, Firebase, custom OIDC (signInWithIdToken)kovlet.auth.signInWithIdToken
db.auth.signInAsGuestkovlet.auth.signInAsGuest
db.useAuth()useAuth()
admin SDK, asUserMachine Auth Key, Kovlet-As-End-User
auth.createTokenPOST …/end-users/{id}/sign-in-codes

Next

Ready to try it? Start free. No credit card, no API keys.

For coding agents: this page is also Markdown. Add .md to the URL or send Accept: text/markdown. The full reference is at /llms-full.txt.