Skip to main content
Memberstack Docs
Dashboard

Pre-built Modals

Memberstack provides professional, ready-to-use modals for login, signup, and profile management. These modals handle all the UI and authentication logic for you, just open them with a single line of code.

/dom-package/pre-built-modals.md
Before You Start
  • Make sure you've initialized Memberstack with your public key
  • Create your plans in the Memberstack dashboard (Plans)
  • Check your site is running on HTTPS for live mode

Login Modal

The login modal provides a complete login interface with email/password, social login (if enabled), and a forgot password option.

// Basic usage
await memberstack.openModal("LOGIN");

// With configuration options
await memberstack.openModal("LOGIN", {
    signup: {
        plans: ["pln_xyz", "pln_abc"]  // Your free plan IDs
    }
});

// With return data handling
memberstack.openModal("LOGIN").then(({ data, type }) => {
    // The promise also resolves when the visitor dismisses the modal:
    // { type: "CLOSED" } with no data. A successful login is type "LOGIN".
    if (type !== "LOGIN") return;

    console.log("Logged in:", data.member.id);

    // The modal stays open after a successful login: close it
    memberstack.hideModal();
});
What's Included
  • Email and password login form
  • Social login buttons (if enabled in Authentication → Auth providers)
  • Forgot password link
  • Optional signup link (for free plans)
  • Error handling and validation

Signup Modal

The signup modal handles new member registration. You can connect it to specific free plans or let members sign up without a plan.

// Basic usage
await memberstack.openModal("SIGNUP");

// With free plans
await memberstack.openModal("SIGNUP", {
    signup: {
        plans: ["pln_xyz", "pln_abc"]  // Your free plan IDs
    }
});

// With data handling
memberstack.openModal("SIGNUP", {
    signup: {
        plans: ["pln_xyz"]
    }
}).then(({ data, type }) => {
    // "CLOSED" means the visitor dismissed the modal without signing up
    if (type === "CLOSED") return;

    // The modal stays open after success: close it yourself
    memberstack.hideModal();

    if (type === "SIGNUP") {
        console.log("Signed up:", data.member.id);
        window.location.href = "/welcome";
    } else if (type === "LOGIN") {
        // The visitor used "Already have an account?" and logged in instead
        window.location.href = data.redirect || "/dashboard";
    }
});
Important Notes
  • Only use free plan IDs in the signup options
  • For paid plans, use purchasePlansWithCheckout instead
  • Get your plan IDs from the Memberstack dashboard (Plans)
  • Remember to close the modal after successful signup

Profile Modal

The profile modal lets members manage their account settings, subscription, and team membership all in one place.

// Basic usage
await memberstack.openModal("PROFILE");

// Open a specific tab: "profile", "plans", "security", "team", or "changePassword"
await memberstack.openModal("PROFILE", {
    profile: { tab: "plans" }
});

// Example function for profile button
function openProfileModal() {
    memberstack.openModal("PROFILE").then(({ type }) => {
        if (type === "LOGOUT") {
            // The member clicked Log out inside the modal.
            // The modal stays open until you close it.
            memberstack.hideModal();
            window.location.href = "/login";
            return;
        }

        // type === "CLOSED": the member dismissed the modal.
        // (With nobody logged in, the profile modal closes straight away
        // and also resolves { type: "CLOSED" }.)
        console.log("Profile modal closed");
    });
}
Available Tabs
  • "profile", Profile information (name, email, custom fields)
  • "plans", Plans & subscription management
  • "security", Password & connected accounts
  • "team", Team settings (if enabled)
  • "changePassword", Change password form
When to Show It
  • After login/signup success
  • From account/profile menu
  • When updating billing
  • Managing team settings

Password Reset Modals

Memberstack provides two modals for password management:

// Open forgot password modal
await memberstack.openModal("FORGOT_PASSWORD");

// Open reset password modal (where members enter their 6-digit code + new password)
await memberstack.openModal("RESET_PASSWORD");
  • FORGOT_PASSWORD, Emails the member a 6-digit reset code
  • RESET_PASSWORD, Where members enter that code and set their new password

Preloading Modals (Performance)

The prebuilt modal UI (~450KB) is lazy-loaded from the Memberstack CDN the first time you call openModal(), so the first open can feel slightly delayed. Call memberstack.preloadModals() to fetch the UI ahead of time, so the first openModal() is instant. It returns Promise<void> that resolves once the UI is loaded, or rejects if the script cannot be loaded after two retries.

// Preload in the background on app load.
// (Catch the rejection: if the script fails to load, openModal() retries.)
memberstack.preloadModals().catch(() => {});

// Later, openModal() will be instant
loginButton.addEventListener("click", () => {
    memberstack.openModal("LOGIN");
});

// Or preload on hover for just-in-time loading
loginButton.addEventListener("mouseenter", () => {
    memberstack.preloadModals().catch(() => {});
});

// You can also await it if you need the UI ready
await memberstack.preloadModals();
console.log("Modals ready!");
When to Preload
  • On app load if you know a modal will likely be opened
  • On hover/focus of a login or signup button for just-in-time loading
  • Safe to call multiple times, the UI is only fetched once
  • Skip it entirely if your app never opens prebuilt modals, the ~450KB is never downloaded

Common Questions

Not after a success. A modal stays open after a successful login or signup, and after a member logs out from the PROFILE modal, until your code calls memberstack.hideModal(). Members can still close a modal themselves at any time: with its close (X) button (the Forgot Password modal has a back arrow instead), by clicking the dark overlay around it, or by pressing Escape while focus is inside the modal. However it is closed, the openModal() promise resolves with { type: "CLOSED" } and no data.

Basic styling can be configured in your Memberstack dashboard under Design → Modal editor.

Every openModal() call (for all modal types, not just login/signup) returns a promise that resolves with an OpenModalResult object holding optional type and data properties. type is "LOGIN" or "SIGNUP" on success, "LOGOUT" when a member logs out from the profile modal, and "CLOSED" when the visitor closes the modal (X button, overlay click or Escape) or you close it with hideModal(), so check type before reading data.

Yes for live mode, but HTTP works in sandbox mode for testing.

If the prebuilt modal script can't be loaded (e.g. blocked by ORB/CORS), openModal() retries twice, logs a [Memberstack] Modal failed to load. console warning, and then rejects (throws) — so wrap the call in try/catch. Check your browser's Network tab for blocked requests; this commonly happens on localhost. See the Troubleshooting section below.

Troubleshooting

Modals Not Appearing on Localhost

If openModal() rejects (throws) with a [Memberstack] Modal failed to load. warning and no modal appears, your browser is likely blocking the modal UI script due to cross-origin restrictions (ORB/CORS). This is a known issue when developing on http://localhost.

Symptoms
  • openModal('LOGIN') rejects (throws) after a brief retry — the promise never resolves
  • A [Memberstack] Modal failed to load. warning appears in the console
  • Browser DevTools Network tab shows net::ERR_BLOCKED_BY_ORB for the modal CDN script

Pre-built modals load an external script from the Memberstack CDN. When running on http://localhost, browsers may block this script due to Origin Read Blocking (ORB). To test modals, deploy to a staging environment with HTTPS, use a local HTTPS proxy, or point window.__MS_PREBUILT_UI_URL__ at a locally-served copy of the modal script before calling openModal(). Always wrap openModal() in try/catch so a blocked script is handled gracefully.

Need help?
Can't find what you're looking for? Our team is here to help.