How to build a SaaS admin dashboard with MRR
Build an admin dashboard with revenue, MRR and users, locked to admins only. The steps by hand, and what Launchfast already ships at /admin.
Short answer: store every payment and subscription in your own database, add an admin role to your users, write one guard that returns a 404 to everyone else, then run a few queries for revenue, MRR, sign-ups and conversion. Launchfast already has this at /admin: requireAdmin() and the analytics queries live in src/lib/admin.ts, and npm run make-admin -- you@example.com makes your account an admin.
Why is an admin dashboard harder than it looks?
The charts are the easy part. The hard parts are underneath:
- You need payment data in your own tables. If it only lives in the payment provider's dashboard, you can't join it to your users.
- "Revenue" needs rules: do refunds count, and which currency do you report in?
- MRR is not the sum of what people paid this month. A yearly plan has to count as one twelfth per month.
- Anyone who guesses
/adminmust not learn that it exists, and a client-side check is not a security check. - Banning a user has to actually end their sessions, not just set a flag.
How do you build it by hand?
- Store payments and subscriptions. Create a
paymenttable (amount, currency, status, created date, user) and asubscriptiontable (status, price, interval). Keep them up to date from your provider's webhooks, with verified signatures and idempotent handlers. This is a project of its own, covered in how to accept payments in your SaaS. - Add a role to users. Your auth library needs a
rolecolumn and a way to check it. Better Auth's admin plugin adds the role and ban fields to the user table. - Write one admin guard. Read the session on the server, check the role, and respond with
notFound()when it isn'tadmin. A 404 instead of a 403 hides that the page exists. - Give yourself the role. There is no admin until you create one. You need a script or a SQL statement that sets
role = 'admin'on your own account after you sign up. - Protect the page and the actions. Check the role in the page itself. Check it again in every server action that changes something, such as banning a user. A redirect in middleware only saves a round trip.
- Decide what revenue means. Count only paid payments, leave out refunded ones, and pick one currency so you don't add dollars to rupees.
- Compute MRR. For each active subscription, convert its price to a monthly amount. Monthly counts once, yearly counts one twelfth, weekly counts 52/12 times. Add them up.
- Compare with the previous period. A revenue number alone says little. Show the change against the same-length period before it.
- Compute sign-ups and conversion. Count users created in the range, then the share of them who have at least one paid payment.
- Build the charts and the user list. Group by day, week or month depending on the range, and add a searchable, paginated user table with a ban button.
- Handle Next.js 16 rendering rules. With
cacheComponentson, reading the session orsearchParamsmust happen inside a component wrapped in<Suspense>, or the build fails.
The traps are steps 5, 6 and 7. Most home-made dashboards get MRR wrong for yearly plans or count refunds as revenue.
What does Launchfast already do?
Launchfast ships the whole page at /admin. Here is what is in the repository.
The guard. requireAdmin() in src/lib/admin.ts reads the user with requireUser() and returns a 404 unless the role is admin:
export async function requireAdmin() {
const current = await requireUser();
if (current.role !== "admin") notFound();
return current;
}
A signed-in user who isn't an admin gets a 404. A visitor who is signed out is sent to sign-in first, by requireUser() and by src/proxy.ts, which only checks that a session cookie exists. The page then calls requireAdmin() itself, so the proxy is not what protects it. The page also sets robots to noindex.
Making yourself admin. Sign up in the app, then run:
npm run make-admin -- you@example.com
scripts/make-admin.mts sets role = 'admin' on that account and tells you if no account exists for the address.
The numbers. getAnalytics() in the same file returns everything the overview needs for a range of 7 days, 30 days, 90 days or 12 months, each compared with the range before it:
- Net revenue: paid payments only, so refunded payments are left out. It uses the settlement amount, which is what reached your balance, in your most common payout currency.
- MRR: active subscriptions converted to a monthly amount, with a table in the code (
perMonth) that counts a yearly price as one twelfth. - New customers, sign-ups and sign-up to paid: a customer is someone with a first successful payment, and conversion is the share of the range's sign-ups who have paid.
- Charts and a per-plan breakdown: revenue and sign-ups per day, week or month, plus revenue by plan.
A table of the latest payments sits below, and then a user list.
The user list. listUsers() searches by name or email, shows 25 users per page, and joins each user's billing status. The Ban and Unban buttons call a server action in src/app/admin/actions.ts:
export async function setBanned(formData: FormData) {
const userId = String(formData.get("userId"));
const ban = formData.get("ban") === "true";
const requestHeaders = await headers();
if (ban) {
await auth.api.banUser({ body: { userId, banReason: "Banned by an admin" }, headers: requestHeaders });
} else {
await auth.api.unbanUser({ body: { userId }, headers: requestHeaders });
}
refresh();
}
The action goes through Better Auth's admin API, which checks that the caller is an admin again, so the role is verified on the action and not only on the page. The admin button for your own account is hidden.
Next.js 16 rules. In src/app/admin/page.tsx, the overview, the payments table and the user list are each wrapped in <Suspense>, and requireAdmin() runs inside those components, so the page works with cacheComponents: true. The admin area is always light, whatever the system theme.
What should you know before relying on it?
The analytics rows are aggregated in memory. A comment in getAnalytics() says this is fine up to tens of thousands of payments, and that you should move the sums into SQL if you outgrow it. The dashboard is also only as good as your webhooks: it reads the payment and subscription tables, which the Dodo and Stripe webhook handlers fill. Revenue is in one currency, so a mix of payout currencies shows only the most common one.
How much does this save?
You skip the role setup, the guard, the second check on actions, the revenue and MRR rules, the charts and the user table. What is left is signing up, running one command and opening /admin.
Launchfast is the starter this post describes. Related reading: how to accept payments in your SaaS, how to add Google and GitHub login to your web app and the checklist to run before launching a SaaS.