Memberstack Playground
Editable examples for the most-used Memberstack DOM package methods. The Run button executes a snippet against a small built-in mock (login, signup, logout, current member and Member JSON), not your app. Copy the samples into your own project to run them for real.
The key field only checks the format of your public key; it does not connect to your app, and nothing you type is sent to Memberstack. (Test mode keys start with pk_sb_.) Snippets for methods the mock does not simulate say so when you run them (the profile image snippet needs a file input on the page, so it stops earlier).
This playground targets developers using the @memberstack/dom package (or Webflow via window.$memberstackDom). If you’re building with Data Attributes (Webflow/WordPress data-attribute integration), refer to the Data Attribute documentation instead.
These examples use programmatic methods, not data-attributes.
Authentication
This section covers user authentication, including signup, login, logout, and handling authentication state changes.
Signup Member (Email/Password)
Signs up a new member using email and password.
Login Member (Email/Password)
Logs in an existing member with email and password.
Logout Member
Logs out the currently authenticated member.
Signup with Provider
Initiates the signup process using a third-party provider (e.g., Google, Facebook). Providers include: Google, Facebook, GitHub, LinkedIn, Spotify, and Dribbble. If Memberstack has set up a custom OIDC provider for your app, pass the key you were given (custom providers cannot be created from the dashboard).
This method opens a popup window for the provider’s sign-in flow, it does not redirect the current page. The returned promise resolves with { data: { member, tokens, redirect } } after the user finishes in the popup, and the member’s session is stored for you automatically. Because it opens a popup, call it from a direct user action (e.g. a click) to avoid popup blockers.
Login with Provider
Initiates the login process using a third-party provider.
This method opens a popup window for the provider’s sign-in flow, it does not redirect the current page. The returned promise resolves with { data: { member, tokens, redirect } } after the user finishes in the popup, and the member’s session is stored for you automatically. Because it opens a popup, call it from a direct user action (e.g. a click) to avoid popup blockers.
Send Passwordless Login Email
Sends a passwordless login email to the specified email address.
Send Passwordless Signup Email
Sends a passwordless signup email to the specified email address.
Login with Passwordless Token
Logs in a member with the 6-digit code from the passwordless login email (it is a code the member types in, not a login link). Pass the code as passwordlessToken.
Signup with Passwordless Token
Signs up a new member with the 6-digit code from the passwordless signup email. Pass the code as passwordlessToken.
On Authentication Change
Listens for changes in the member’s authentication state (login, logout, signup). The provided callback function is called whenever the authentication state changes, and receives the updated member object (or null if logged out).
Get Member Cookie
Retrieves the current member’s authentication token. Returns the token string if the member is logged in, or undefined otherwise.
Send Verification Email
Sends an email verification email to the currently logged-in member.
Pre-built Modals
This section demonstrates how to use Memberstack’s pre-built modals for common authentication and profile management actions.
The openModal method takes the modal type as the first argument and an optional object of parameters as the second. It returns a Promise that resolves once, with { type, data }: "LOGIN" or "SIGNUP" on success, "LOGOUT" when a member logs out from the PROFILE modal, or { type: "CLOSED" } (no data) when the modal is closed first. After a login, signup or logout the modal stays open until you call memberstack.hideModal(). Members can close it themselves with the close (X) button, by clicking the dark overlay, or by pressing Escape while focus is inside the modal.
- Available modal types:
LOGIN,SIGNUP,FORGOT_PASSWORD,RESET_PASSWORD,PROFILE - Some modals accept parameters, e.g. the
SIGNUPmodal takessignup: { plans: ["pln_..."] }(an array of free plan IDs) to attach plans to the new member:memberstack.openModal("SIGNUP", { signup: { plans: ["YOUR_FREE_PLAN_ID"] } }).
Open Modal
Opens a pre-built Memberstack modal.
Hide Modal
Closes the currently open Memberstack modal. The hideModal method does not take any arguments.
Profile Management
This section covers methods for managing the current member’s profile, including updating custom fields, and changing passwords.
Get Current Member
Retrieves the currently logged-in member’s data. The method takes an optional object with a useCache property, set to true to return cached member data if available, or false (default) to always fetch the latest from the server.
Update Member
Updates the current member’s custom fields. The updateMember method takes an object with a customFields property containing the fields to update.
Delete Member
Deletes the current member’s account. Member self-deletion must be enabled for your app in the dashboard (it is off by default); otherwise the call rejects with “Please contact the website owner to delete your account.” On success the member is logged out immediately and the account is permanently deleted. By default their active Stripe subscriptions are cancelled and the Stripe customer is kept; both behaviours follow your app’s self-deletion settings.
Once an account is deleted, it cannot be recovered.
Update Member Authentication
Updates the current member’s authentication details (email, password). The updateMemberAuth method takes an object with optional email, oldPassword (required if changing the password), and newPassword properties.
Update Member JSON
Stores or updates arbitrary JSON data for the current member, perfect for user preferences, app settings, progress tracking, and custom metadata.
This method does NOT merge. To preserve existing data, fetch the current JSON first, modify it, then update.
Get Member JSON
Retrieves arbitrary JSON data stored for the current member. The response is shaped as { data }, where data is the stored JSON object directly (there is no nested .json property). data is null or an empty object {} if no data exists.
Send Password Reset Email
Sends a password reset email to the specified email address. The method returns a generic success message for security reasons, regardless of whether the email exists in the system.
Reset Member Password
Resets a member’s password using a reset token sent to a member.
Connect Provider
Connects a third-party provider (e.g., Google, Facebook) to the current member’s account.
Disconnect Provider
Disconnects a third-party provider from the current member’s account.
Update Member Profile Image
Updates the current member’s profile image. The method takes a file object from a file input element and uploads it to update the member’s profile image.
Plan Management
This section covers methods for managing the current member’s plans, including adding, removing, and purchasing plans.
Get Plan
Retrieves information about a specific plan. The method takes a planId parameter and returns the plan details if found.
Get Plans
Retrieves a list of all available plans. The method resolves to { data: plans }, where plans is an array of plan objects, each containing its ID, name, description, priority, and associated prices. status is only returned by getPlan().
Add Plan
Adds a free plan to the current member’s account. The method takes a planId parameter and adds the specified plan to the member’s account if they don’t already have it. A plan with prices rejects with the code plan-not-free: paid plans go through purchasePlansWithCheckout.
Remove Plan
Removes a free plan from the current member’s account. The method takes a planId parameter and removes the specified plan from the member’s account if they have it. Paid plans cannot be removed this way; send the member to launchStripeCustomerPortal() to cancel.
Purchase Plans with Checkout
Initiates a Stripe Checkout session to purchase a plan (via its priceId).
Launch Stripe Customer Portal
Launches the Stripe Customer Portal for the current member to manage their subscriptions and payment methods. You can read more about the Stripe Customer Portal configuration here.
- For paid plans, use test card
4242 4242 4242 4242 - Free plans use
planId, paid plans usepriceId - Check the Memberstack dashboard (Plans) for your actual IDs
Data Tables
This section demonstrates Data Tables functionality for storing and managing structured data with powerful querying capabilities, relationships, and access control.
Reads apply to getDataTables, getDataTable, getDataRecord, getDataRecords and queryDataRecords (GET /v1/data-tables, GET /v1/data-tables/:tableKey, POST /v1/data-records/query)
- Global: 200 requests per 30 seconds per IP
- Reads: 25 requests per second per IP (GET/query operations)
- Creates: 10 requests per minute per IP (POST operations)
- Writes: 30 requests per minute per IP (PUT/DELETE operations)
If DISABLE_DATA_TABLES is truthy on the server, all routes return 503 with message: “Data table feature is temporarilly offline.”
- Create test tables in your Memberstack dashboard (Data Tables) first
- Use realistic test data for better understanding
- Check access rules, some operations may require authentication
- Use table keys (not IDs) in your requests
- Record IDs are opaque strings (cuids, e.g.
cm3x9k2p40001js0f8h1e2a7b) with no prefix; use theidreturned by a create or query
Get Data Tables
Retrieve all available data tables and their schemas.
Get Data Table
Retrieve detailed information about a specific data table by its key (table).
Create Data Record
Create a new record in a data table. Takes a table key and a data object containing the field values for the new record.
Get Data Record
Retrieve a specific record by ID from a data table. Takes a table key and a recordId.
Update Data Record
Update specific fields in an existing data record. Only the fields you specify will be changed.
Delete Data Record
Permanently delete a specific record from a data table. Deletion cannot be undone.
Query Data Records
Perform advanced queries with filtering, sorting, pagination, and includes. Pass a flat query object (where / include / select / orderBy / take / skip / after / _count), the SDK wraps it as findMany automatically.
Other Methods
This section covers miscellaneous methods and utilities.
Get Secure Content (Hosted Content)
Retrieves secure content associated with the current member based on a hosted content ID. For a hosted file (type: "FILE"), content is a download link that works for 5 minutes and file has its name, mimeType, size, expiresAt and expiresIn. Pass download: true to have a PDF or image saved instead of opened.
Set Password
Sets a first password (at least 8 characters) for a logged-in member who signed up with passwordless or a social provider. To change an existing password, use updateMemberAuth({ oldPassword, newPassword }).
FAQs
Here are some common questions and answers about using Memberstack in your projects:
You can find your Memberstack public key in your Memberstack dashboard. Go to Developer → Keys & IDs. Test mode keys start with pk_sb_, live keys with pk_.
Custom fields allow you to store additional information about your members, such as their preferences, profile details, or any other data relevant to your application. You can define custom fields in the Memberstack dashboard under Members > Custom Fields and then use the Memberstack API (e.g., updateMember, signupMemberEmailPassword) to set and update their values.
To integrate Memberstack, you first need to include the Memberstack DOM package in your website’s code. Since the DOM package is designed for use with package managers, you can install it using npm or yarn: npm install @memberstack/dom or yarn add @memberstack/dom. Then, import the package into your code and initialize the Memberstack object with your public key using Memberstack.init({ publicKey: "YOUR_PUBLIC_KEY" }). After that, you can use the various Memberstack methods to add authentication, manage members, and control access to content.
While team methods exist within the DOM package, they are not officially documented or supported for direct implementation. For the best experience with team functionality, we strongly recommend using Memberstack’s pre-built profile modal instead of attempting to implement these methods yourself.
Memberstack supports several authentication methods, including:
- Email/Password: Members sign up and log in using their email address and a password.
- Passwordless: Members log in by receiving a one-time code via email.
- Social Login: Members can authenticate using their existing accounts with providers like Google, Facebook, GitHub, LinkedIn, Spotify, and Dribbble. Custom OIDC providers that Memberstack has set up for your app are also supported.
Memberstack API methods return promises that either resolve with the requested data or reject with an error object. You should always use try...catch blocks to handle potential errors. Memberstack errors are usually plain objects shaped as { code, message, category?, suggestions?, docsUrl? }. The primary field for programmatic handling is code (a kebab-case string, e.g. "invalid-credentials"); message is a human-readable description, category groups related errors, suggestions offers actionable fixes, and docsUrl links to documentation for that error. The HTTP status is not on the error object. Calls that need a logged-in member can also reject with the plain string "Unauthorized" when there is no session, so check typeof error === "object" before reading error.code.
You can define redirect URLs in the Memberstack dashboard under Plans > Default Settings > Redirects for different actions like login, signup, and logout (these apply to all members and can be overridden per plan). Some methods also accept redirect URLs directly: purchasePlansWithCheckout accepts successUrl and cancelUrl, and launchStripeCustomerPortal accepts a returnUrl. (Note that addPlan takes only a planId and does not accept a redirect URL.)
Memberstack works well with static site generators like SvelteKit, Next.js, Gatsby, etc. You can use the Memberstack DOM package on the client-side to handle authentication and member management. For dynamic content or server-side interactions, you can use serverless functions or a backend API to communicate with Memberstack’s API.
Yes, Memberstack is designed to work seamlessly with SPAs. The Memberstack DOM package provides methods for handling authentication, managing members, and controlling content access within your SPA.
You can customize the appearance of Memberstack’s pre-built modals using CSS. Memberstack provides CSS classes that you can target to override the default styles. You can also use JavaScript to add or remove classes and modify the modal’s behavior.
- Use test mode keys (starting with
pk_sb_) for development - Remember to handle errors in your code
- Check the console for additional debugging information
- Replace placeholder IDs with your actual plan and price IDs
- Create test accounts with fake email addresses (e.g., test@example.com)
- Use secure but memorable passwords for testing
- Test mode allows up to 50 test members
- Test members can be deleted to free up space