Skip to main content

Memberstack for v0

Paid memberships for your v0 app, live on Vercel

Keep building your Next.js app in v0. Memberstack runs the logins, Stripe plans and members-only pages from Client Components.

In v0

v0 has no login of its own. Name Memberstack so it doesn't add another.

On your live app

your-app.vercel.app/members
Memberstack's login modal on the published v0 app

Seven steps, in order

One environment variable, one command in v0's terminal, and short messages to v0. The code is what v0 should write, so you can check it.

01

Copy your public key

It's in your Memberstack dashboard and starts with pk_. It's safe in the browser. Your secret key never goes in a v0 project.

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

Add it in Environment Variables

Open the project menu (…), then Settings, then Environment Variables. Only names that start with NEXT_PUBLIC_ reach the browser, which is what the public key needs. Include Development, or v0's preview won't see it.

Settings → Environment Variables

NEXT_PUBLIC_MEMBERSTACK_PUBLIC_KEY=pk_your_public_key
03

Install the SDK in v0's terminal

Open the Console and pick the Terminal tab. npm is already there. No terminal in your chat? Ask v0 to install the package.

npm install @memberstack/dom
04

Set up the SDK in a client file

v0 builds in Next.js by default, so the SDK must only start in the browser. This file creates it on first use. Ask v0 to add it, or paste it in the Code tab and save.

lib/memberstack.ts

"use client";

import memberstackDOM from "@memberstack/dom";

let instance: ReturnType<typeof memberstackDOM.init> | undefined;

// Created in the browser on first use, never during server rendering
export function getMemberstack() {
  instance ??= memberstackDOM.init({
    publicKey: process.env.NEXT_PUBLIC_MEMBERSTACK_PUBLIC_KEY!, // pk_...
  });
  return instance;
}
05

Use Memberstack for login

v0 has no login of its own; if you ask it for auth, it may reach for Supabase. Pick one place for members to log in: say Memberstack handles it. These buttons open Memberstack's modals.

components/auth-buttons.tsx

"use client";

import { getMemberstack } from "@/lib/memberstack";

// Opens a Memberstack modal and closes it once the member is in
// (modals stay open after a successful login or sign-up)
async function open(kind: "LOGIN" | "SIGNUP") {
  const ms = getMemberstack();
  const { type } = await ms.openModal(kind);
  if (type !== "CLOSED") ms.hideModal();
}

export function AuthButtons() {
  return (
    <>
      <button onClick={() => open("LOGIN")}>Log in</button>
      <button onClick={() => open("SIGNUP")}>Sign up</button>
    </>
  );
}
06

Gate pages by plan

Wrap members-only content in this Client Component. Only ACTIVE or TRIALING plans get in. Everyone else sees a link to your plans.

components/members-only.tsx

"use client";

import { useEffect, useState } from "react";
import { getMemberstack } 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 = getMemberstack();
    // 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. When the member comes back, the plan is already on their account.

// Upgrade button: Stripe Checkout, then back to your app
await getMemberstack().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 v0 one message

Add the variable and run the install first. Then swap in your plan and price IDs from the Memberstack dashboard and paste this into v0's chat.

Don't add Supabase Auth or any other login; Memberstack handles members. Create lib/memberstack.ts as a "use client" module that exports getMemberstack(), which initialises @memberstack/dom on first use with process.env.NEXT_PUBLIC_MEMBERSTACK_PUBLIC_KEY. Log in and Sign up buttons call getMemberstack().openModal("LOGIN") and openModal("SIGNUP"), then close it with hideModal() once the member is in. Only members with plan pln_pro whose status is ACTIVE or TRIALING can see /members, and re-check when someone logs in or out. Add an upgrade button that starts Stripe Checkout for price prc_pro_monthly.
FAQ

v0 and Memberstack questions answered

Setup, plans, payments and security.

No. Add one environment variable, run one install command in v0's terminal, then paste the prompt on this page with your own plan and price IDs. The code on this page is what the result looks like, so you can check it in the Code tab.

In the project menu, under Settings, then Environment Variables, named NEXT_PUBLIC_MEMBERSTACK_PUBLIC_KEY. Next.js only sends NEXT_PUBLIC_ variables to the browser, and v0 may flag one as a risk. That's expected here: the public key is meant to be public. Your secret key never gets that prefix.

v0 builds Next.js apps by default, and they render on the server first. The browser SDK needs a browser, so it starts on first use inside Client Components. For anything that must stay private on the server, verify the member with @memberstack/admin.

No. Keep Supabase for data if you use it, but pick one place for members to log in. Say in the prompt that Memberstack handles members.

Click Publish in the chat header. v0 deploys to Vercel and gives your app a vercel.app address. You can add your own domain in the project settings.

Your v0 app, with members

Keep your members on Memberstack.

Logins, Stripe plans and members-only pages for the Next.js app you built in v0.

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