Skip to main content

Memberstack for Replit

Paid memberships for your Replit app, live on replit.app

Keep building with Replit's Agent. Name Memberstack instead of Clerk for your logins, Stripe plans and members-only pages.

In Replit

Agent adds Clerk for login unless you name a provider. Name Memberstack.

On your live app

your-app.replit.app/members
Memberstack's login modal on the published Replit app

Seven steps, in order

One message to Agent does most of it. The code is what Agent should write, so you can check it.

01

Copy your public key

It's in your Memberstack dashboard and starts with pk_. It's made for the browser. Your secret key never goes in the front end.

Public keypk_••••••••••••
02

Tell Agent to skip its own login

When you ask Replit's Agent for login without naming a provider, it adds Clerk (Replit Auth on Enterprise). Pick one place for members to log in: say Memberstack handles it.

Tell Agent“Don't add Clerk or Replit Auth. Memberstack handles sign-up and login.”

03

Install the SDK

Ask Agent to install it, or open the Shell tool and run this yourself.

npm install @memberstack/dom
04

Set up the SDK with your key

The key goes in the code, not in Secrets. Replit's Secrets are for values that must stay off the browser, and this key is meant for the browser.

src/lib/memberstack.ts

import memberstackDOM from "@memberstack/dom";

// The public key is meant for the browser, so it can sit in the code
export const memberstack = memberstackDOM.init({
  publicKey: "pk_your_public_key",
});
05

Add Log in and Sign up

These buttons open Memberstack's login and sign-up modals in your app.

// Run SDK calls in the browser: click handlers or useEffect.
// Modals stay open after a successful login or sign-up, so close them.
async function open(kind: "LOGIN" | "SIGNUP") {
  const { type } = await memberstack.openModal(kind);
  if (type !== "CLOSED") memberstack.hideModal();
}

<button onClick={() => open("LOGIN")}>Log in</button>
<button onClick={() => open("SIGNUP")}>Sign up</button>
06

Gate pages by plan

Members-only pages check the member's plans. Only ACTIVE or TRIALING plans get in. Everyone else sees a link to your plans.

src/components/MembersOnly.tsx

import { useEffect, useState } from "react";
import { memberstack } from "@/lib/memberstack";

const PRO_PLAN_ID = "pln_pro"; // your plan ID from the Memberstack dashboard

type Member = { planConnections?: { planId: string; status: string }[] } | null;

// Only ACTIVE or TRIALING plans get in
const hasPro = (member: Member) =>
  !!member?.planConnections?.some(
    (p) => p.planId === PRO_PLAN_ID && (p.status === "ACTIVE" || p.status === "TRIALING"),
  );

export function MembersOnly({ children }: { children: React.ReactNode }) {
  const [state, setState] = useState<"loading" | "allowed" | "blocked">("loading");

  useEffect(() => {
    const ms = memberstack;
    // Check now, then again whenever someone logs in, signs up or logs out
    ms.getCurrentMember().then(({ data }) => setState(hasPro(data) ? "allowed" : "blocked"));
    const { unsubscribe } = ms.onAuthChange((member) =>
      setState(hasPro(member) ? "allowed" : "blocked"),
    );
    return () => {
      unsubscribe();
    };
  }, []);

  if (state === "loading") return null;
  if (state === "blocked") return <p>Members only. <a href="/pricing">See plans</a>.</p>;
  return <>{children}</>;
}
07

Take payments with Memberstack's Checkout

Upgrade buttons open Stripe Checkout through Memberstack, so the plan lands on the member's account. You don't need Replit's own Stripe connector for this.

// Upgrade button: Stripe Checkout, then back to your app
await memberstack.purchasePlansWithCheckout({
  priceId: "prc_pro_monthly", // your Memberstack price ID (prc_...)
  successUrl: "/members",
  cancelUrl: "/pricing",
});

Hiding a page isn't protecting it

The plan check decides what the browser shows. If a file or an API response must stay private, verify the member token on your server with @memberstack/admin and verifyToken, passing your app ID as the audience.

Or send Replit one message

Swap in your public key, plan and price IDs from the Memberstack dashboard and paste this into Agent.

Don't add Clerk, Replit Auth or any other login; Memberstack handles members. Install @memberstack/dom and create src/lib/memberstack.ts that initialises it with my public key pk_your_public_key (it's a public key, so keep it in the code, not in Secrets). The Log in and Sign up buttons call memberstack.openModal("LOGIN") and memberstack.openModal("SIGNUP"), then close it with hideModal() once the member is in. Only let members with plan pln_pro whose status is ACTIVE or TRIALING see /members, and re-check when someone logs in or out. Add an upgrade button that starts Stripe Checkout with memberstack.purchasePlansWithCheckout for price prc_pro_monthly.
FAQ

Replit and Memberstack questions answered

Setup, plans, payments and security.

No. Paste the prompt on this page into Agent with your own key, plan and price IDs. Agent installs the SDK itself. The code on this page is what the result looks like, so you can check what Agent wrote.

Replit's Agent uses Clerk by default when you don't name a provider (Replit Auth on Enterprise plans). Say in your prompt that Memberstack handles members, so they log in one place.

No. Replit's Secrets are for values that must stay off the browser, and the public key has to run there. Put it in the code. Your Memberstack secret key is the one that never goes in the front end.

You don't need it for memberships. Memberstack opens Stripe Checkout and adds the plan to the member when they pay. Connect Stripe in your Memberstack dashboard instead.

Click Publish at the top right of the Project Editor. Replit publishes your app to a .replit.app address, and Autoscale is the default.

Your Replit app, with members

Keep your members on Memberstack.

Logins, Stripe plans and members-only pages for the app you built with Replit's Agent.

  • No credit card required
  • Same members on every platform
$35M · Relume, company, from a component library
Relume website