Also available: Markdown version · llms.txt · full site content
Authentication
Anonymous users
Let visitors use your app before they create an account. An anonymous user is a real user with a real id — and converting them later keeps every row they wrote, with a password or with Google (no password needed).
Enable anonymous sign-ins
Open the provider settings
Console → your project → Auth → Providers → Anonymous users.
Switch on Allow anonymous sign-ins
The setting is off by default. Turning it off later blocks new anonymous sessions but does not touch existing ones.
Sign a visitor in
POST /auth/v1/signup/anonymous needs no email or password. CubiBase creates a real user in auth.users with is_anonymous set and returns the same session shape as a normal signup.
POST https://example-project.api.cubibase.com/auth/v1/signup/anonymous
apikey: cb_pub_EXAMPLE_ONLY
Content-Type: application/json
{
"data": { "cart": ["item-1"] }
}{
"user": {
"id": "3f2b8c1e-9a47-4d02-b6e5-1c8f0a3d7e29",
"email": null,
"isAnonymous": true,
"providers": [],
"mfaEnabled": false
},
"accessToken": "<ACCESS_JWT>",
"refreshToken": "<REFRESH_TOKEN>",
"tokenType": "Bearer",
"expiresIn": 3600
}The access token works like any other end-user JWT: its sub is the user id, so rows written with a user column already belong to that visitor.
Convert to a real account
An anonymous visitor becomes a real account in place — same user id, same rows. There are two ways to do it, and Google never asks for a password:
| Path | What the visitor does | What you send |
|---|---|---|
| Email + password | Types an email and chooses a password | PATCH /auth/v1/user with the anonymous bearer token, email, and password |
| Clicks “Continue with Google” — Google proves who they are | The anonymous bearer token on /auth/v1/authorize or grant_type=id_token |
- The user id does not change on either path — the rows they created stay theirs.
- Existing sessions keep working; no re-login is forced.
- Metadata is merged with the Google profile (name, picture).
Path 1 · email and password
When the visitor is ready to register with an email, convert the account with PATCH /auth/v1/user, sending the anonymous bearer token plus an email and a password.
PATCH https://example-project.api.cubibase.com/auth/v1/user
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <ANONYMOUS_ACCESS_JWT>
Content-Type: application/json
{
"email": "mina@example.com",
"password": "<USER_PASSWORD>"
}Path 2 · Google (no password)
The trick is one header: send the anonymous user’s access token as Authorization: Bearer … on the Google sign-in request. CubiBase then links the Google identity to that user instead of creating a new one. Both Google flows support it.
Browser redirect flow
Start the flow with the anonymous bearer token
Call GET /auth/v1/authorize?provider=google&redirect_to=… with the apikey header and the anonymous access token as the bearer. CubiBase remembers the user id inside the single-use state.
The visitor consents at Google
Open the returned url in the browser. Google shows its consent screen — no CubiBase password is involved at any point.
The callback converts the account
Google redirects back to CubiBase, which links the identity to the remembered user: the email comes from the Google profile, is_anonymous is cleared, and the user id stays the same.
Store the new session
The browser lands on your redirect_to with a fresh token pair in the URL fragment (amr: ["oauth"]). Replace the anonymous pair with it; the old anonymous session keeps working until it expires or is revoked.
GET https://example-project.api.cubibase.com/auth/v1/authorize?provider=google&redirect_to=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <ANONYMOUS_ACCESS_JWT>ID-token flow (mobile and web SDKs)
If your app already holds a Google ID token from Google Sign-In, post it to the id_token grant with the same anonymous bearer token. The response is a normal session for the converted user.
POST https://example-project.api.cubibase.com/auth/v1/token?grant_type=id_token
apikey: cb_pub_EXAMPLE_ONLY
Authorization: Bearer <ANONYMOUS_ACCESS_JWT>
Content-Type: application/json
{
"provider": "google",
"idToken": "<GOOGLE_ID_TOKEN>"
}Managing anonymous users
In the Console user directory, anonymous users carry an Anonymous badge and can be filtered separately. From the SQL editor you can inspect them directly:
SELECT count(*) AS anonymous_users
FROM auth.users
WHERE is_anonymous;