Guides
Guest Sessions

Guest Sessions

Guest sessions allow users to interact with your dApp before signing up. A temporary Canton party is allocated for the guest, and when they register, their guest wallet merges into their real account.

How It Works

  1. Guest visits your dApp and clicks "Continue as Guest"
  2. PartyLayer creates a temporary session with a Canton party
  3. Guest can submit transactions, view contracts, and interact normally
  4. When the guest signs up, their data is automatically converted to a full account

Configuration

Enable guest sessions in your SDK config:

const pl = new PartyLayerEnterprise({
  appId: 'app_xxx',
  apiKey: 'pk_live_xxx',
  guest: {
    enabled: true,
    sessionTtlMinutes: 1440, // 24 hours (default)
    autoConvertOnLogin: true, // auto-merge on signup (default)
  },
});

React Integration

Show Guest Option in LoginButton

import { LoginButton } from '@partylayer/enterprise-react';
 
function App() {
  return (
    <LoginButton
      providers={['auth0', 'passkey']}
      showGuestOption
      onGuestStart={() => console.log('Guest session started')}
    />
  );
}

useGuest Hook

import { useGuest } from '@partylayer/enterprise-react';
 
function GuestBanner() {
  const { session, isActive, createSession, convert, expireSession } = useGuest();
 
  if (!isActive) return null;
 
  return (
    <div>
      <p>You are browsing as a guest. Sign up to save your progress.</p>
      <button onClick={expireSession}>Leave Guest Mode</button>
    </div>
  );
}

SDK Methods

// Create a guest session
const session = await pl.guest.create();
 
// Check if guest session is active
if (pl.guest.isActive()) {
  // Guest is active
}
 
// Convert guest to full user
const result = await pl.guest.convert({
  email: 'alice@example.com',
  name: 'Alice',
  auth0Id: 'auth0|abc123',
});
 
// Expire guest session
await pl.guest.expire();

Auto-Convert on Login

When autoConvertOnLogin is enabled (default), the guest session is automatically converted when the user logs in through any auth provider. The guest's Canton party and any associated data are merged into the new user account.

Events

EventDescription
guest:createdGuest session was created
guest:convertedGuest was converted to a full user
guest:expiredGuest session expired or was manually ended

REST API

MethodEndpointDescription
POST/api/v1/guestsCreate guest session
GET/api/v1/guests/:idGet guest session
POST/api/v1/guests/:id/convertConvert to full user
DELETE/api/v1/guests/:idExpire session
POST/api/v1/guests/cleanupBulk expire old sessions