Interface: MemberNamespace
Defined in: types.ts:239
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:309
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:261
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:270
Returns
boolean
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:285
Parameters
| Parameter | Type |
|---|---|
jwt | string |
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:298
Parameters
| Parameter | Type |
|---|---|
slug | string |
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:487
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | string | Provider slug, e.g. "google". |
Returns
Promise<ExternalProfileAttributes>
Example
const profile = await allegro.member.externalProfile('google');
console.log(profile.email, profile.name);
Magic Link
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()
requestMagicLink(
returnUrl?,data?):Promise<MagicLinkRequestResponse>
Defined in: types.ts:344
Parameters
| Parameter | Type | Description |
|---|---|---|
email | string | The member's email address. |
returnUrl? | string | URL 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(
'[email protected]',
'https://example.com/dashboard',
{ plan: 'pro', source: 'homepage' },
);
Magic Link
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()
validateMagicLink(
token):Promise<MagicLinkValidateResponse>
Defined in: types.ts:366
Parameters
| Parameter | Type | Description |
|---|---|---|
token | string | The 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(
Promise<IdentifySessionResponse>
Defined in: types.ts:414
Parameters
| Parameter | Type | Description |
|---|---|---|
email | string | The email address to associate with this session. |
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:429
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:458
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:446
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:467
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:392
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | string | Provider 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);
}