Advanced Integration
Advanced Memberstack integration features including webhooks, custom authentication flows, and API endpoints for building sophisticated membership experiences.
This guide covers advanced integration features of Memberstack, including webhooks, custom authentication flows, and API endpoints. These features allow you to build sophisticated membership experiences and integrate deeply with your existing systems.
- Complete the Quick Start Guide
- Familiarize yourself with the Memberstack dashboard
- Have a paid Memberstack plan for production use
Webhooks
Webhooks are not part of the DOM package: Memberstack sends them to an endpoint on your server, never to the browser, so the DOM package does not receive them. They complement it by letting your backend respond to events like member creation, updates, and plan changes. To react to logins, signups and logouts in the browser, use onAuthChange (see Authentication State Management).
Available Events
member.created, When a new member signs upmember.updated, When member data changesmember.deleted, When a member is removed
member.plan.added, When a member gets a new planmember.plan.updated, When a plan status changesmember.plan.canceled, When a plan is canceled
team.member.added, When a member is added to a teamteam.member.removed, When a member is removed from a team
Setting Up Webhooks
- Go to the Memberstack dashboard
- Navigate to Developer → Webhooks
- Enable webhooks and add your endpoint URL
- Select the events you want to receive
- Copy your webhook secret for verification
Example Webhook Payload
{
"event": "member.created",
"timestamp": 1633486880169,
"payload": {
"id": "mem_...",
"auth": {
"email": "john@example.com"
},
"metaData": {},
"customFields": {},
"verified": false,
"stripeCustomerId": null,
"planConnections": [
{
"status": "ACTIVE",
"planId": "pln_...",
"planConnectionId": "con_..."
}
]
}
}Provider Authentication
The DOM package supports OAuth/social provider authentication through four methods: loginWithProvider, signupWithProvider, connectProvider, and disconnectProvider. These open a popup window to complete the provider flow and return the authenticated member data. If the popup is blocked or closed, the promise stays pending and the SDK fires a memberstack:popup event instead; see Blocked or Closed Popups.
The provider value is a built-in provider key — google, facebook, github, linkedin, spotify, or dribbble. If Memberstack has set up a custom OpenID Connect (OIDC) provider for your app, pass the key you were given as a plain string. Custom providers cannot be created from the dashboard: the dashboard's Custom SSO page is a different feature, where Memberstack acts as the identity provider for other apps.
- Enable and configure each provider in your Memberstack dashboard before calling these methods — under Authentication → Auth providers
- Provider keys are lowercase, e.g.
google - See Core Authentication for the full authentication surface
Login & Signup with a Provider
Use loginWithProvider for existing members and signupWithProvider to create a new member. Both open a popup and resolve with the authenticated member.
// Log in an existing member with a provider
const { data } = await memberstack.loginWithProvider({
provider: "google",
allowSignup: false // optional (default false): set true to create an account if none exists
});
console.log("Logged in:", data.member.auth.email);// Sign up a new member with a provider
const { data } = await memberstack.signupWithProvider({
provider: "google",
customFields: { referralSource: "twitter" }, // optional
plans: [{ planId: "pln_starter" }], // optional
inviteToken: "..." // optional, team invite token
});
// If this provider account is already connected to a member, that member is
// logged in instead (customFields and plans are then ignored). If the email
// belongs to a member who has not connected this provider, the call rejects
// by default, e.g. with the message "Please login with your email."
console.log("Signed up:", data.member.auth.email);// A custom OIDC provider key that Memberstack set up for your app
// (custom providers cannot be created from the dashboard)
const { data } = await memberstack.loginWithProvider({
provider: "my-custom-oidc"
});Connect & Disconnect Providers
A logged-in member can link additional providers with connectProvider and remove them with disconnectProvider. The member must keep at least one usable login method.
// Connect a provider to the current member's account
await memberstack.connectProvider({ provider: "google" });
// Member can now log in with email/password or Google// Disconnect a provider from the current member's account
await memberstack.disconnectProvider({ provider: "google" });
// Member must use another connected method to log inAvailable Packages
Alongside the Admin REST API, Memberstack offers packages for different environments that allow you to extend and customize your Memberstack integration.
Admin Package
- Verify JWT tokens
- Validate webhook signatures
- Manage members server-side
Other Packages
- DOM Package (this documentation)
- Data Attribute Package (Webflow & Wordpress)
Using the Admin Package
// Example using the Admin Package (server-side only)
import memberstackAdmin from "@memberstack/admin";
const memberstack = memberstackAdmin.init(process.env.MEMBERSTACK_SECRET_KEY);
// `token` is the member's JWT, sent from the browser
// (for example in an Authorization: Bearer header)
try {
// Rejects if the token is invalid, expired, or issued for a different app.
// Always pass audience (your app ID): without it, a valid token from any
// other Memberstack app also verifies.
const { id } = await memberstack.verifyToken({
token,
audience: process.env.MEMBERSTACK_APP_ID
});
// Use the id from the verified token, never one supplied by the client.
// retrieve() resolves { data: null } if the member no longer exists.
const { data: member } = await memberstack.members.retrieve({ id });
console.log("Member data:", member);
} catch (error) {
// Not authenticated
}- DOM Package: Client-side member management and authentication
- Admin Package: Server-side only operations and security validation
- Data Attribute Package: Wrapper around the DOM package that adds data attributes