Auth

Google sign-in (OAuth)

Let users of your product (web, mobile, or internal tool) sign in with their Google account. This guide applies to any application wired to Kuunda Auth — not only a migration scenario.

1. How the flow works

Google does not talk to your frontend directly. Kuunda Auth sits in the middle: it receives the Google callback, creates or looks up the user, then sends the session back to your application.

  1. The user clicks Continue with Google in your app.
  2. The browser is redirected to Kuunda Auth (/auth/v1/authorize).
  3. Kuunda Auth redirects to Google (consent screen).
  4. Google calls Kuunda Auth back at theredirect URI (callback).
  5. Kuunda Auth redirects to your Site URL / redirectTo with a session (fragment #access_token=…).

When it completes, the user exists under Auth → Users and your app can call the API (REST, Storage, and so on) with the JWT.

2. The three URLs (do not mix them up)

Most mistakes come from mixing these addresses. They do not play the same role.

URLWhere you set itRole
Google redirect URI

https://api.kuunda-cloud.com/auth/v1/callback

Google Cloud → OAuth clientCallback Google → Kuunda Auth. This is not your site URL.
Site URLKuunda → Auth → ProvidersDefault destination after login (your frontend origin, with a trailing slash if the console shows one).
Redirect URLsKuunda → Auth → ProvidersAllowlist of redirectTo values your SDK may request (localhost, preview, prod).

Copy the URI shown in Kuunda

The console (Google card, Redirect URIalert) shows the exact value for your project. On SaaS (shared Auth), it is almost always https://api.kuunda-cloud.com/auth/v1/callback — not the {ref}.kuunda-cloud.comsubdomain. No trailing slash.

3. Create the Google OAuth client

You can create a new client, or reuse an existing client (another backend, previous stack, internal tool): add the Kuunda URI to the redirect list, alongside URIs already there, until cutover is complete.

  1. Open Google Cloud → Credentials.
  2. Create (or open) a Web application client — not Android, iOS, or Desktop app.
  3. Give it a readable name (e.g. Kuunda — My app).
  4. Under Authorized redirect URIs, add exactly:
    https://api.kuunda-cloud.com/auth/v1/callback
    If the project uses dedicated Auth (Enterprise plan), the URI may be:
    https://{ref}.kuunda-cloud.com/auth/v1/callback
  5. Under Authorized JavaScript origins, add at least:
    • https://api.kuunda-cloud.comshared Auth
    • https://app.kuunda-cloud.comthe Test button in the console
    • https://{ref}.kuunda-cloud.comAPI via the project subdomain
    • Your frontend origin: https://app.exemple.ci, and http://localhost:3000 locally
  6. Save, then copy the Client ID and the Client secret.

The Google consent screen (branding, domains, test users in Testing mode) must be published, or in development your Google account must be listed as a test user.

4. Configure the Kuunda project

In the console: https://app.kuunda-cloud.com → your project → Auth → Providers.

Project URLs

On the Site URL / redirects card:

Enable Google

  1. Expand the Google card.
  2. Check Enable Google.
  3. Paste the Client ID and the Client secret.
  4. Check the redirect URIalert: the same value must be listed in Google Cloud.
  5. Save — the badge switches to Enabled.

5. Test

  1. Open a private browsing window (avoids a Google account already linked by mistake).
  2. In the Kuunda console, use the Test button on the Google card — or start the flow from your app (next section).
  3. Choose a Google account and accept the permissions.
  4. You should land on the Site URL with a #access_token=… fragment (and usually refresh_token).
  5. Under Auth → Users, the user appears (Google email, identity custom:proj-{ref}-google).

6. Integrate in your application

Use the @kuunda/kuunda-jsSDK. Project URL and anonkey: Settings → API in the console. Never expose the service_role key in the browser.

Initialize the client

import { createClient } from '@kuunda/kuunda-js';

const kuunda = createClient(
  'https://{ref}.kuunda-cloud.com',
  'kuunda_anon_…',
  { projectRef: '{ref}' }
);

“Continue with Google” button

await kuunda.auth.signInWithOAuth({
  provider: 'google',
  options: {
    redirectTo: 'https://app.exemple.ci/auth/callback',
  },
});

In the browser, this method redirects immediately to Kuunda Auth. redirectTo must be listed in the project’s Redirect URLs. projectRef is required so that provider: 'google' is rewritten to the project’s provider.

Provider name (SDK vs HTTP)

Kuunda Auth reserves google, github, facebook, apple, azure, x. Kuunda therefore registers a custom provider per project, using hyphens (identifier without underscores).

ProviderSDKHTTP /authorize
Googlegooglecustom:proj-{ref}-google
GitHubgithubcustom:proj-{ref}-github
Facebookfacebookcustom:proj-{ref}-facebook
Appleapplecustom:proj-{ref}-apple
Microsoft (Azure)azurecustom:proj-{ref}-azure
X (Twitter)x (twitter alias)custom:proj-{ref}-x

provider=google through the gateway

On https://{ref}.kuunda-cloud.com, /auth/v1/authorize?provider=google is rewritten to custom:proj-{ref}-google (you do not need to pass the custom identifier by hand). Prefer @kuunda/kuunda-js anyway. On the api.host, pass apikey in the query string and the project ref (subdomain or header).

Without the SDK (HTTP)

Equivalent (project subdomain — apikey is optional on that host; recommended elsewhere):

https://{ref}.kuunda-cloud.com/auth/v1/authorize?provider=google&redirect_to=https%3A%2F%2Fapp.exemple.ci%2Fauth%2Fcallback

Explicit form, always valid: provider=custom:proj-{ref}-google&apikey=kuunda_anon_…

After the redirect back

Kuunda Auth returns the session in the URL fragment (#access_token=…&refresh_token=…). On the destination page:

Scopes

By default, Google provides basic identity (email, profile). For extra scopes, pass options.scopes and declare them on the Google consent screen as well.

7. Production checklist

8. Troubleshooting

SymptomLikely causeWhat to do
redirect_uri_mismatchThe URI sent to Google does not match the OAuth client (often the project subdomain instead of the API host).Paste the URI from the Kuunda alert. On SaaS: https://api.kuunda-cloud.com/auth/v1/callback.
invalid_api_keyAuthorize without the anon key, or the wrong key.Reload Providers; the test URL must include apikey=kuunda_anon_….
Redirect error after Googleredirect_to / Site URL not on the Auth allowlist.Add the exact origin under Auth → project URLs.
Unsupported providerHTTP provider=google (reserved), wrong SDK, or SDK alias without projectRef. Same trap for GitHub, Apple, and so on.SDK: @kuunda/kuunda-js + projectRef. HTTP: custom:proj-{ref}-google (hyphens).
Google “unverified app” screenConsent screen in Testing mode / app not published.Add the account as a test user, or publish the consent screen.
No user in the consoleThe flow stopped before the Kuunda callback, or the wrong project.Check the Client ID of the right project, and that Google is Enabled + Saved.

Next