Create and update Customers, issue Customer Tokens, and handle Guests and claims after login.
API v1Updated
Create or find a Customer
Use the verified user ID from your system as externalUserId. Calling again with the same ID returns the same Customer (created: false) and leaves its profile unchanged.
Register your website origin under SDK integration → Allowed website origins in Console.
The issuing Key needs sessions:create plus the scopes the browser uses, such as entitlements:read.
Tokens renew while in use, up to 30 days; after expiry, sign the user in again.
Support signed-out users
Generate a guestToken for the visitor, keep it in an HttpOnly cookie and exchange it for a Customer Token. After login, call claimGuestCustomer to bind it to the account.
guest.tsTypeScript
1import { createGuestToken, createIndianaServer } from"@tinkerlandai/indiana-sdk/server";23const indiana = createIndianaServer({4 baseUrl: process.env.INDIANA_API_URL!,5 apiKey: process.env.INDIANA_API_KEY!,6 scope: { projectId: process.env.INDIANA_PROJECT_ID!, environment: "sandbox" },7});89// 1. First visit: create the guest token once and keep it in an HttpOnly cookie.10exportasyncfunctionstartGuest(savedGuestToken?: string) {11const guestToken = savedGuestToken ?? createGuestToken();12await indiana.createGuestCustomer({ guestToken });13const session = await indiana.resumeGuestSession({ guestToken });14return { guestToken, customerToken: session.customerToken };15}1617// 2. After your own login succeeds: bind the guest to the verified account.18exportasyncfunctionclaimGuest(input: {19 guestToken: string;20 verifiedUserId: string;21 requestId: string;22}) {23const { customer, switched } = await indiana.claimGuestCustomer({24 guestToken: input.guestToken,25 externalUserId: input.verifiedUserId,26 requestId: input.requestId,27 });28const { customerToken } = await indiana.createCustomerSession(customer.id);29return { customerToken, switched };30}