Skip to main content

Interface: MemberNamespace

Defined in: types.ts:249

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:337

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:271

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:280

Returns

boolean

Authentication

Returns the raw session JWT string, or null if no valid JWT is present or the token has expired.

Use this to authenticate against your own backend: send the token as a bearer header and verify it against the tenant's JWKS endpoint.

getJwt()

getJwt(): string | null

Defined in: types.ts:313

Returns

string | null

Example

const jwt = allegro.member.getJwt();
if (jwt) {
fetch('/api/user', { headers: { Authorization: `Bearer ${jwt}` } });
}

Authentication

Stores the given JWT as the active session, persisting it to both the in-memory store and the device session cookie.

Use this when your application obtains a JWT through its own flow and needs to hand it to the SDK.

setJwt()

setJwt(jwt): void

Defined in: types.ts:295

Parameters

ParameterType
jwtstring

Returns

void

Example

allegro.member.setJwt(jwtFromMyServer);

Entitlements

Returns true if the member's JWT contains the given product slug in the products claim.

hasProduct()

hasProduct(slug): boolean

Defined in: types.ts:326

Parameters

ParameterType
slugstring

Returns

boolean

Example

if (allegro.member.hasProduct('voter-game-plan')) {
// show gated content
}

External Profiles

Fetches the external profile data for the authenticated member from the given OAuth provider (e.g. "google").

Returns the raw attributes stored for that provider. The shape varies by provider — cast the result to a more specific type when needed.

Throws if the member is not authenticated or no profile exists for the provider.

externalProfile()

externalProfile(provider): Promise<ExternalProfileAttributes>

Defined in: types.ts:581

Parameters

ParameterTypeDescription
providerstringProvider slug, e.g. "google".

Returns

Promise<ExternalProfileAttributes>

Example

const profile = await allegro.member.externalProfile('google');
console.log(profile.email, profile.name);

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:372

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('[email protected]');

// With a custom return URL and extra data
await allegro.member.requestMagicLink(
'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:394

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);

OTP

Request a combined magic link and one-time code in a single email.

Emails both a magic sign-in link and a six-digit code. Unlike {@link requestLoginCode}, this DOES start background auth polling so that clicking the link in any browser authenticates this session while the code input is shown.

requestMagicLinkOtp()

requestMagicLinkOtp(email, returnUrl?, data?): Promise<MagicLinkOtpRequestResponse>

Defined in: types.ts:429

Parameters

ParameterTypeDescription
emailstringThe member's email address.
returnUrl?stringURL the member is redirected to after authenticating. Defaults to the current page URL.
data?Record<string, unknown>Arbitrary key/value data to store on the resulting session.

Returns

Promise<MagicLinkOtpRequestResponse>

OTP

Request a one-time passcode email for the given address.

Emails a six-digit code. Unlike {@link requestMagicLink}, this does NOT start background auth polling — the user enters the code on this device and {@link validateLoginCode} completes authentication synchronously.

requestLoginCode()

requestLoginCode(email, returnUrl?, data?): Promise<OtpRequestResponse>

Defined in: types.ts:413

Parameters

ParameterTypeDescription
emailstringThe member's email address.
returnUrl?stringURL the member is redirected to after authenticating. Defaults to the current page URL.
data?Record<string, unknown>Arbitrary key/value data to store on the resulting session.

Returns

Promise<OtpRequestResponse>

OTP

Validate a one-time passcode entered by the member. On success the session JWT is stored and an allegro:authenticated event is dispatched. On failure an {@link AllegroApiError} is thrown with errorCode one of INVALID_OTP, OTP_LOCKED.

validateLoginCode()

validateLoginCode(code): Promise<OtpValidateResponse>

Defined in: types.ts:444

Parameters

ParameterTypeDescription
codestringThe six-digit code entered by the member.

Returns

Promise<OtpValidateResponse>

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, data?): Promise<IdentifySessionResponse>

Defined in: types.ts:508

Parameters

ParameterTypeDescription
emailstringThe email address to associate with this session.
data?Record<string, unknown>-

Returns

Promise<IdentifySessionResponse>

Example

await allegro.member.identifyByEmail('[email protected]');

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:523

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:552

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:540

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:561

Returns

Promise<void>

Social Login

Authenticate via a third-party OAuth provider by navigating the current window, instead of opening a popup. Used when the page itself is already a popup (e.g. the OAuth authorize page opened by a partner), where a nested popup would be unreliable or blocked.

The provider redirects back to returnUrl once authentication completes; this method never resolves because the current page navigates away.

loginWithProviderRedirect()

loginWithProviderRedirect(provider, returnUrl, data?): void

Defined in: types.ts:486

Parameters

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

Returns

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:470

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);
}

User Attributes

Clears the authenticated member's value for a user attribute. The session JWT is refreshed automatically.

deleteUserAttribute()

deleteUserAttribute(slug): Promise<void>

Defined in: types.ts:618

Parameters

ParameterTypeDescription
slugstringThe attribute slug.

Returns

Promise<void>

User Attributes

Lists the user attributes defined by the organization together with the authenticated member's current value for each (null when unset).

getUserAttributes()

getUserAttributes(): Promise<UserAttributeValue[]>

Defined in: types.ts:593

Returns

Promise<UserAttributeValue[]>

Example

const attributes = await allegro.member.getUserAttributes();

User Attributes

Sets the authenticated member's value for a user attribute. The server validates the value against the attribute's declared type and returns the stored (cast) value. The session JWT is refreshed automatically.

setUserAttribute()

setUserAttribute(slug, value): Promise<unknown>

Defined in: types.ts:609

Parameters

ParameterTypeDescription
slugstringThe attribute slug.
valueunknownThe value to store.

Returns

Promise<unknown>

Example

await allegro.member.setUserAttribute('wants-newsletter', true);