# Interface: MemberNamespace

Defined in: [types.ts:239](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L239)

Methods for authenticating and identifying audience members.

Access this namespace via `allegro.member`.

## Example[​](#example "Direct link to Example")

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

```

## Authentication[​](#authentication "Direct link to Authentication")

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

### logout()[​](#logout "Direct link to logout()")

> **logout**(): `Promise`<`void`>

Defined in: [types.ts:309](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L309)

#### Returns[​](#returns "Direct link to Returns")

`Promise`<`void`>

#### Example[​](#example-1 "Direct link to Example")

```ts
await allegro.member.logout();

```

## Authentication[​](#authentication-1 "Direct link to 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 "Direct link to isAuthenticated()")

> **isAuthenticated**(): `boolean`

Defined in: [types.ts:261](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L261)

#### Returns[​](#returns-1 "Direct link to Returns")

`boolean`

#### Example[​](#example-2 "Direct link to Example")

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

```

## Authentication[​](#authentication-2 "Direct link to 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 "Direct link to isIdentified()")

> **isIdentified**(): `boolean`

Defined in: [types.ts:270](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L270)

#### Returns[​](#returns-2 "Direct link to Returns")

`boolean`

## Authentication[​](#authentication-3 "Direct link to 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 "Direct link to setJwt()")

> **setJwt**(`jwt`): `void`

Defined in: [types.ts:285](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L285)

#### Parameters[​](#parameters "Direct link to Parameters")

| Parameter | Type     |
| --------- | -------- |
| `jwt`     | `string` |

#### Returns[​](#returns-3 "Direct link to Returns")

`void`

#### Example[​](#example-3 "Direct link to Example")

```ts
allegro.member.setJwt(jwtFromMyServer);

```

## Entitlements[​](#entitlements "Direct link to Entitlements")

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

### hasProduct()[​](#hasproduct "Direct link to hasProduct()")

> **hasProduct**(`slug`): `boolean`

Defined in: [types.ts:298](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L298)

#### Parameters[​](#parameters-1 "Direct link to Parameters")

| Parameter | Type     |
| --------- | -------- |
| `slug`    | `string` |

#### Returns[​](#returns-4 "Direct link to Returns")

`boolean`

#### Example[​](#example-4 "Direct link to Example")

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

```

## External Profiles[​](#external-profiles "Direct link to 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 "Direct link to externalProfile()")

> **externalProfile**(`provider`): `Promise`<`ExternalProfileAttributes`>

Defined in: [types.ts:487](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L487)

#### Parameters[​](#parameters-2 "Direct link to Parameters")

| Parameter  | Type     | Description                     |
| ---------- | -------- | ------------------------------- |
| `provider` | `string` | Provider slug, e.g. `"google"`. |

#### Returns[​](#returns-5 "Direct link to Returns")

`Promise`<`ExternalProfileAttributes`>

#### Example[​](#example-5 "Direct link to Example")

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

```

## Magic Link[​](#magic-link "Direct link to 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 "Direct link to requestMagicLink()")

> **requestMagicLink**(`email`, `returnUrl?`, `data?`): `Promise`<[`MagicLinkRequestResponse`](/developer/api-reference/type-aliases/MagicLinkRequestResponse.md)>

Defined in: [types.ts:344](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L344)

#### Parameters[​](#parameters-3 "Direct link to 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[​](#returns-6 "Direct link to Returns")

`Promise`<[`MagicLinkRequestResponse`](/developer/api-reference/type-aliases/MagicLinkRequestResponse.md)>

#### Example[​](#example-6 "Direct link to Example")

```ts
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' },
);

```

## Magic Link[​](#magic-link-1 "Direct link to 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 "Direct link to validateMagicLink()")

> **validateMagicLink**(`token`): `Promise`<[`MagicLinkValidateResponse`](/developer/api-reference/type-aliases/MagicLinkValidateResponse.md)>

Defined in: [types.ts:366](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L366)

#### Parameters[​](#parameters-4 "Direct link to Parameters")

| Parameter | Type     | Description                                 |
| --------- | -------- | ------------------------------------------- |
| `token`   | `string` | The one-time token from the magic link URL. |

#### Returns[​](#returns-7 "Direct link to Returns")

`Promise`<[`MagicLinkValidateResponse`](/developer/api-reference/type-aliases/MagicLinkValidateResponse.md)>

#### Example[​](#example-7 "Direct link to Example")

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

```

## Session[​](#session "Direct link to 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 "Direct link to identifyByEmail()")

> **identifyByEmail**(`email`): `Promise`<[`IdentifySessionResponse`](/developer/api-reference/type-aliases/IdentifySessionResponse.md)>

Defined in: [types.ts:414](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L414)

#### Parameters[​](#parameters-5 "Direct link to Parameters")

| Parameter | Type     | Description                                       |
| --------- | -------- | ------------------------------------------------- |
| `email`   | `string` | The email address to associate with this session. |

#### Returns[​](#returns-8 "Direct link to Returns")

`Promise`<[`IdentifySessionResponse`](/developer/api-reference/type-aliases/IdentifySessionResponse.md)>

#### Example[​](#example-8 "Direct link to Example")

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

```

## Session[​](#session-1 "Direct link to 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-2 "Direct link to session()")

> **session**(): `Promise`<[`SessionResponse`](/developer/api-reference/type-aliases/SessionResponse.md)>

Defined in: [types.ts:429](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L429)

#### Returns[​](#returns-9 "Direct link to Returns")

`Promise`<[`SessionResponse`](/developer/api-reference/type-aliases/SessionResponse.md)>

#### Example[​](#example-9 "Direct link to Example")

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

```

## Session[​](#session-3 "Direct link to Session")

Fetches the member's active entitlements.

### entitlements()[​](#entitlements-1 "Direct link to entitlements()")

> **entitlements**(): `Promise`<[`MemberEntitlement`](/developer/api-reference/interfaces/MemberEntitlement.md)\[]>

Defined in: [types.ts:458](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L458)

#### Returns[​](#returns-10 "Direct link to Returns")

`Promise`<[`MemberEntitlement`](/developer/api-reference/interfaces/MemberEntitlement.md)\[]>

#### Example[​](#example-10 "Direct link to Example")

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

```

## Session[​](#session-4 "Direct link to 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 "Direct link to sessionFromJwt()")

> **sessionFromJwt**(): [`MemberJwtPayload`](/developer/api-reference/type-aliases/MemberJwtPayload.md) | `null`

Defined in: [types.ts:446](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L446)

#### Returns[​](#returns-11 "Direct link to Returns")

[`MemberJwtPayload`](/developer/api-reference/type-aliases/MemberJwtPayload.md) | `null`

#### Example[​](#example-11 "Direct link to Example")

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

```

## Session[​](#session-5 "Direct link to 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 "Direct link to refreshJwtIfNeeded()")

> **refreshJwtIfNeeded**(): `Promise`<`void`>

Defined in: [types.ts:467](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L467)

#### Returns[​](#returns-12 "Direct link to Returns")

`Promise`<`void`>

## Social Login[​](#social-login "Direct link to 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 "Direct link to loginWithProvider()")

> **loginWithProvider**(`provider`, `data?`): `Promise`<[`SocialLoginResponse`](/developer/api-reference/type-aliases/SocialLoginResponse.md)>

Defined in: [types.ts:392](https://github.com/alleyinteractive/allegro/blob/6aebbf1d5d34ded3d128c093d7d30abd96d938be/packages/allegro-platform/resources/js/sdk/types.ts#L392)

#### Parameters[​](#parameters-6 "Direct link to 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[​](#returns-13 "Direct link to Returns")

`Promise`<[`SocialLoginResponse`](/developer/api-reference/type-aliases/SocialLoginResponse.md)>

#### Example[​](#example-12 "Direct link to Example")

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

```
