Skip to main content

Interface: MemberNamespace

Defined in: types.ts:200

Methods for authenticating and identifying audience members.

Access this namespace via allegro.member.

Example

window.allegro.push((allegro) => {
if (allegro.member.isAuthenticated()) {
const payload = allegro.member.sessionFromJwt();
console.log('Hello,', payload?.audience_member.name);
}
});

Authentication

Logs the current member out, clears the session JWT, and dispatches allegro:logout.

logout()

logout(): Promise<void>

Defined in: types.ts:242

Returns

Promise<void>

Example

await allegro.member.logout();

Authentication

Returns true if the current session has a valid, authenticated JWT.

An authenticated session means the member has completed a login flow (magic link, social login, etc.). An identified-but-not-authenticated session only has an email association.

isAuthenticated()

isAuthenticated(): boolean

Defined in: types.ts:222

Returns

boolean

Example

if (allegro.member.isAuthenticated()) {
showMemberContent();
} else {
showLoginPrompt();
}

Authentication

Returns true if the session has a stored JWT — either identified or fully authenticated.

Use this to check whether an email has been associated with the session without requiring a completed login.

isIdentified()

isIdentified(): boolean

Defined in: types.ts:231

Returns

boolean

Request a magic link email for the given address.

Sends an email containing a one-time login link. The session is also marked as "identified" so the member can be associated with future events before they click the link.

After calling this, the SDK automatically polls for authentication in the background — no manual polling is needed.

requestMagicLink(email, returnUrl?, data?): Promise<MagicLinkRequestResponse>

Defined in: types.ts:277

Parameters

ParameterTypeDescription
emailstringThe member's email address.
returnUrl?stringURL the member is redirected to after clicking the link. Defaults to the current page URL.
data?Record<string, unknown>Arbitrary key/value data to store on the resulting session (e.g. referral source, plan selection).

Returns

Promise<MagicLinkRequestResponse>

Example

await allegro.member.requestMagicLink('user@example.com');

// With a custom return URL and extra data
await allegro.member.requestMagicLink(
'user@example.com',
'https://example.com/dashboard',
{ plan: 'pro', source: 'homepage' },
);

Validate a magic link token from the URL query string.

You typically don't call this directly — the SDK validates the ?allegro_token= query parameter automatically on page load.

validateMagicLink(token): Promise<MagicLinkValidateResponse>

Defined in: types.ts:299

Parameters

ParameterTypeDescription
tokenstringThe one-time token from the magic link URL.

Returns

Promise<MagicLinkValidateResponse>

Example

const token = new URLSearchParams(location.search).get('allegro_token') ?? '';
const result = await allegro.member.validateMagicLink(token);
console.log(result.return_url);

Session

Associates an email address with the current anonymous session without requiring a full login.

Use this to identify a member before they authenticate — for example, when they enter their email on a registration form. The session will appear as "identified" but not "authenticated".

identifyByEmail()

identifyByEmail(email): Promise<IdentifySessionResponse>

Defined in: types.ts:347

Parameters

ParameterTypeDescription
emailstringThe email address to associate with this session.

Returns

Promise<IdentifySessionResponse>

Example

await allegro.member.identifyByEmail('user@example.com');

Session

Fetches live session data from the API.

Includes authentication status, timestamps, and the associated audience member record if the session is identified.

session()

session(): Promise<SessionResponse>

Defined in: types.ts:362

Returns

Promise<SessionResponse>

Example

const { data } = await allegro.member.session();
console.log(data.is_authenticated, data.audience_member?.email);

Session

Fetches the member's active entitlements.

entitlements()

entitlements(): Promise<MemberEntitlement[]>

Defined in: types.ts:391

Returns

Promise<MemberEntitlement[]>

Example

const entitlements = await allegro.member.entitlements();
const hasPro = entitlements.some((e) => e.name === 'pro');

Session

Reads session data from the JWT stored in the browser cookie — no network request required.

Returns null if no valid JWT is present or the token has expired.

sessionFromJwt()

sessionFromJwt(): MemberJwtPayload | null

Defined in: types.ts:379

Returns

MemberJwtPayload | null

Example

const payload = allegro.member.sessionFromJwt();
if (payload) {
console.log('Member ID:', payload.sub);
}

Session

Silently refreshes the JWT if it was issued more than 24 hours ago.

Called automatically on SDK initialisation. Safe to call manually if needed — it is a no-op when the token is still fresh.

refreshJwtIfNeeded()

refreshJwtIfNeeded(): Promise<void>

Defined in: types.ts:400

Returns

Promise<void>

Social Login

Authenticate via a third-party OAuth provider using a popup window.

The list of available providers is configured per tenant (allegro.tenant.loginProviders).

loginWithProvider()

loginWithProvider(provider, data?): Promise<SocialLoginResponse>

Defined in: types.ts:325

Parameters

ParameterTypeDescription
providerstringProvider slug, e.g. "google" or "apple".
data?Record<string, unknown>Arbitrary key/value data to store on the resulting session.

Returns

Promise<SocialLoginResponse>

Example

try {
const result = await allegro.member.loginWithProvider('google');
console.log('Logged in, token:', result.token);
} catch (err) {
console.error('Login failed or popup was blocked:', err);
}