Skip to main content
You are here: Passport JS SUI SDK

Passport JS Events

Overview

Passport triggers various events based on the user interactions with the platform.

Handling Events

Subscribe Early

To capture events, register your event listeners before invoking the init method.

const start = async () => {
passport.on('LOGIN', async (data) => {
console.log('LOGGED IN');
});
await passport.init();
}

window.onload = function() {start();}

In case you need some data, like user data in your subscription, that is available only after init, you can do this:

const initPromise = passport.init();
passport.on('LOGIN', async (data) => {
await initPromise

// get any data here
console.log('LOGGED IN');
});

Generic Onetime Event

An example how to handle any supported onetime event from Passport

typescript
passport.once(Passport.events[eventName], (data) => {
  console.log(data)
})

Generic Event with subscription

An example how to handle any supported event from Passport

typescript
const unsubscribe = passport.on(Passport.events[eventName], (data) => {
  console.log(data)
})

Supported Events

Supported Events

In this section, we list and explain the different types of events that Passport JS can handle. Each event type corresponds to a user or system action on the platform.

ERROR

Handles error events.

INIT

Fired when initialization completes.

LOGIN

Triggered upon user login.

Event Data:

typescript
{
  aud: string;
  email: string;
  exp: number;
  iat: number;
  iss: string;
  login_type: string;
  name: string;
  nonce: string;
  phone: string;
  scope: string;
  sub: string;
  token_type: string;
  token_use: string;
}

LOGOUT

Triggered upon user logout.

SEND_TOKENS

Occurs when tokens are sent.

Event Data:

typescript
{
  suiNetwork: string;
  clientId: string;
  from: string;
  to: string;
  balanceChanges?: BalanceChange[] | null;
  checkpoint?: string | null;
  confirmedLocalExecution?: boolean | null;
  digest: string;
  effects?: TransactionEffects | null;
  errors?: string[];
  events?: SuiEvent[] | null;
  objectChanges?: SuiObjectChange[] | null;
  rawEffects?: number[];
  rawTransaction?: string;
  timestampMs?: string | null;
  transaction?: SuiTransactionBlock | null;
}

RECHECK_BALANCE

Event Data:

typescript
string[];

UPDATE_PROFILE

Occurs when a user updates their profile.

Event Data:

typescript
{
  aud: string;
  email: string;
  exp: number;
  iat: number;
  iss: string;
  login_type: string;
  name: string;
  nonce: string;
  pending: {
    email?: string;
    phone?: string;
  };
  phone: string;
  scope: string;
  sub: string;
  token_type: string;
  token_use: string;
}

ACCOUNT_CONFIRMED

Triggered when an account is confirmed.

Event Data:

typescript
{
  name?: string;
  email?: string;
  phone?: string;
}

TRANSACTION (DEPRECATED)

Fires on any transaction event.

RECEIPT

Fired when a receipt is generated.

Event Data:

typescript
{
  stripeChargeId: string;
}

REQUEST_AIRDROP

Occurs when an airdrop is requested.

Event Data:

typescript
{
  balanceChanges?: BalanceChange[] | null;
  checkpoint?: string | null;
  confirmedLocalExecution?: boolean | null;
  digest: string;
  effects?: TransactionEffects | null;
  errors?: string[];
  events?: SuiEvent[] | null;
  objectChanges?: SuiObjectChange[] | null;
  rawEffects?: number[];
  rawTransaction?: string;
  timestampMs?: string | null;
  transaction?: SuiTransactionBlock | null;
}

REQUEST_LOYALTY_POINTS

Fires when loyalty points are requested.