Skip to content

Docs

Quickstart

Add Sign in with Google to a JavaScript, React, Node or Laravel app. For every option, see the SDK reference on GitHub.
  1. Step 1: Create a workspace

    Sign up and pick your workspace's address, like acme.authxi.com. That address is the issuer your apps use. Set who can sign in under the workspace's access rules.

  2. Step 2: Create an app

    In the workspace, add an application and pick its type:

    • Web app for server-rendered apps (Node, Laravel). It gets a client secret.
    • Single-page app for code that runs in the browser (React, plain JavaScript). It uses PKCE, with no secret.
    • Native for mobile and desktop apps.

    Add your callback URL, for example https://app.acme.com/auth/callback. authxi only returns to registered URLs, matched exactly. For local work, create a separate app marked as development: it also accepts http://localhost on any port.

    Copy the client id, and the client secret for a web app. The secret is shown once.

  3. Step 3: Add the code

    Pick your stack. Each SDK handles PKCE, state, nonce and ID token checks, and returns the page the user started on as returnTo.

    Terminal
    npm install @authxi/js
    auth.ts
    import { createAuthxi } from '@authxi/js';
    
    export const authxi = createAuthxi({
        issuer: 'https://acme.authxi.com',
        clientId: 'app_...',
        redirectUri: `${location.origin}/auth/callback`,
    });
    
    // Sends the user to sign in. returnTo defaults to the current page.
    await authxi.login();
    On /auth/callback
    const { user, returnTo } = await authxi.handleRedirect();
    location.replace(returnTo); // the page they started on
  4. Step 4: Try it

    Sign out, then open a page deep in your app, like /billing/invoices?tab=due. You go through Google, then land back on that page, signed in. The sign-in shows up in the dashboard's sign-in log.

    If your browser app calls your own API, send the ID token along and check it there. Server apps already have the verified user from the callback.

    api.ts
    import { verifyIdToken } from '@authxi/js';
    
    // On your API, for ID tokens your browser app sends
    const claims = await verifyIdToken(token, {
        issuer: 'https://acme.authxi.com',
        audience: 'app_...', // your client id
    });
  5. Step 5: Next

    • Ask for two-step verification before sensitive actions with step-up checks.
    • Handle access_denied and other errors on your callback page.
    • Read the SDK reference for sign-out, silent sign-in and Express middleware.