Memberstack for Lovable
Paid memberships for your Lovable app, set up in the chat
Keep building in Lovable's chat. Ask it to install one SDK, and Memberstack runs your logins, Stripe plans and members-only pages.
In Lovable
Name Memberstack in the prompt, or Lovable adds its own login instead.
On your live app
“Great service - I am very impressed by how easy it is to integrate their service into an existing site.”
Six steps, in order
Each one is a short message to Lovable or a value you paste in. The code is what Lovable should write, so you can check it.
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 Lovable project.
Put it in .env, not Secrets
Lovable keeps browser values in .env as VITE_ variables. Its Secrets are for backend values and refuse VITE_ names. On the Free plan the code is read-only, so ask Lovable to add the line.
.env
VITE_MEMBERSTACK_PUBLIC_KEY=pk_your_public_key
Ask Lovable to install the SDK
Name @memberstack/dom in the project chat. Lovable installs packages for you; there's no terminal step. Then have it set up the SDK with your key. It starts on first use in the browser.
src/lib/memberstack.ts
import memberstackDOM from "@memberstack/dom";
let instance: ReturnType<typeof memberstackDOM.init> | undefined;
// Created in the browser on first use, never while a server renders the page
export function getMemberstack() {
instance ??= memberstackDOM.init({
publicKey: import.meta.env.VITE_MEMBERSTACK_PUBLIC_KEY, // pk_..., from .env
});
return instance;
}Tell Lovable that Memberstack handles login
Ask for login and Lovable adds its own built-in sign-in, so name Memberstack. The Log in and Sign up buttons open Memberstack's modals.
// 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 ms = getMemberstack();
const { type } = await ms.openModal(kind);
if (type !== "CLOSED") ms.hideModal();
}
<button onClick={() => open("LOGIN")}>Log in</button>
<button onClick={() => open("SIGNUP")}>Sign up</button>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 { 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}</>;
}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 Lovable one message
Swap in your plan and price IDs from the Memberstack dashboard, then paste it into the project chat.
Install @memberstack/dom. Create src/lib/memberstack.ts that exports getMemberstack(), which initialises @memberstack/dom on first use in the browser with my public key from VITE_MEMBERSTACK_PUBLIC_KEY in .env. Use Memberstack for login and sign-up, not Lovable's built-in login: the Log in and Sign up buttons call getMemberstack().openModal("LOGIN") and 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 for price prc_pro_monthly.Lovable and Memberstack questions answered
Setup, plans, payments and security.
No. Lovable writes it. 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 what Lovable produced.
No. Pick one place for members to log in. If you ask Lovable for login without naming Memberstack, it sets up its own sign-in, so say Memberstack in the prompt.
In .env as VITE_MEMBERSTACK_PUBLIC_KEY. Lovable treats VITE_ values as browser values and keeps them in .env. Its Secrets manager is for backend values and refuses VITE_ names. Your Memberstack secret key never goes in the project.
Yes. New Lovable projects use TanStack Start, which renders pages on the server first, and older ones use React + Vite. The SDK here starts on first use in the browser, and its methods run from click handlers or useEffect, so the same code works in both.
Paid plans use Stripe Checkout. Your app calls purchasePlansWithCheckout with a Memberstack price ID (prc_...), the member pays on Stripe's page, and they come back to your app with access already granted. Free plans use a plan ID (pln_...) and are added with addPlan.
A plan connection grants access when its status is ACTIVE or TRIALING. Other statuses, such as REQUIRES_PAYMENT when a Stripe payment fails, do not grant access.
No. Client-side checks only control what the browser shows. Anything sensitive, such as a file or an API response, should be checked on your server with @memberstack/admin and verifyToken, passing your app ID as the audience.
Your Lovable app, with members
Keep your members on Memberstack.
Logins, Stripe plans and members-only pages for the app you built in Lovable.
- No credit card required
- Same members on every platform


