Skip to content

Frontend quickstart

Add sign-in the way you would add Firebase Auth. You never handle OAuth nonces, ephemeral keys, zero-knowledge proofs or Enoki.

You need your OctaP API URL, your organization ID and OctaP’s Google client ID, with your site’s origin added to that client.

auth.ts
import { createOctapAuth } from '@octap/browser-sdk';
export const auth = createOctapAuth({
apiBaseUrl: 'https://your-octap-api.example',
organizationId: 'your-organization-id',
googleClientId: 'octap-google-client-id',
});

None of these values are secret. The API key stays on your server.

<div id="sign-in"></div>
await auth.renderGoogleButton(document.getElementById('sign-in'), {
onError: (error) => showMessage(error.message),
});

Signing in also enrolls the customer in your organization. The button renders nothing while a customer is signed in, and returns when they sign out or their session expires.

auth.onAuthStateChanged((user) => {
if (user) {
// { endUserId, memberId, suiAddress }
showAccount(user.memberId);
} else {
showSignedOut();
}
});

The listener also runs once on load, after a reload restores the session. auth.currentUser gives the same value at any time.

Send the customer’s token to your backend, and verify it there. Never trust a member ID your frontend sends on its own.

const response = await fetch('/api/balance', {
method: 'POST',
headers: { authorization: `Bearer ${await auth.getIdToken()}` },
});

Balance, history and voucher calls need your API key, so they run on your backend through @octap/sdk. The Browser SDK does not make them.

await auth.signOut();