How to limit free trials in a Next.js SaaS
A Next.js free trial limit stops one account claiming twice. The server-side code, where it belongs, and why 20 accounts still get 20 trials.
$6,732 is the invoice your model provider just sent you, the morning after your launch. Your usual month costs $1,400. A minute ago your phone was showing the best number your product has ever had, 1,240 new free trials since yesterday evening, and you took a screenshot for your co-founder.
You open the usage page expecting a bug, and there isn't one. Stay with this scenario, because the arithmetic is the bad part. Your trial lasts 14 days and includes 500 AI runs at $0.03 each, so a fully used trial costs you $15. You sort the new accounts by usage, and 380 of them hit exactly 500 runs within hours. Say that's 19 people with 20 accounts each.
380 accounts x 500 runs x $0.03 = $5,700
860 real trials x 40 runs x $0.03 = $1,032
Total overnight = $6,732You had a Next.js free trial limit for exactly this. It runs on the server, it has a test, and it worked all night: not one account got two trials. Your auth library kept every email address unique. Your database refused every second claim. Each did what its documentation says, and none of those documents ever said it could tell when 20 accounts belong to one person. You're finding that out from an invoice.
At 7:52 a customer on your $49 plan writes in: "Exports have been failing since about 1 a.m. We present to our board at 10. What's going on?" Those 190,000 scripted runs (380 × 500) filled your provider's rate limit, so your paying customers spent the night queuing behind accounts that will never pay you. All 64 of them together bring in $3,136 a month, which means one night cost you more than two months of revenue. Say 12 ask for the month back. That's another $588.
So $5,700 plus $588 is $6,288 you never meant to spend. With $38,000 in the bank and $9,500 going out each month, about 20 days of runway disappeared since yesterday evening ($6,288 ÷ $9,500 × 30). The 1,240 you posted about last night is really 860, and people have already seen the bigger number. Nothing stops those 19 people coming back tonight. Five nights like this one is $28,500, three quarters of what's in your account.
Before 9 a.m., with the launch post still climbing, you have to choose. You can switch off the trial while more people are arriving than ever will again, or put a card requirement on the page you just sent them to. Or you can leave it on and find out tonight what that costs.
Why a Next.js free trial limit counts accounts
Next.js has no idea what a trial is. It gives you places to run code on the server, and that code knows what the session tells it: an account ID. So the natural limit is one trial per account ID.
A new account gets a new ID, and the limit has nothing to compare it with. The obvious fix is unique email addresses, which you probably had on day one. That stops the same address twice, and someone with a second address is simply a new row. Build the server-side limit anyway, because without it a single account can restart its trial whenever it likes.
The usual server-side limit in Next.js
Let the database decide, and run the check next to the work it protects. Start with one table:
create table trial_claims (
account_id text primary key,
trial_ends_at timestamp not null,
runs_used integer not null default 0
);Then send every way of starting a trial through one Server Action. requireAccount and db are your own helpers.
"use server";
import { redirect } from "next/navigation";
import { requireAccount } from "@/lib/auth";
import { db } from "@/lib/db";
const TRIAL_DAYS = 14;
export async function startTrial() {
const account = await requireAccount();
const endsAt = new Date(Date.now() + TRIAL_DAYS * 86_400_000);
const result = await db.query(
`insert into trial_claims (account_id, trial_ends_at)
values (?, ?)
on conflict (account_id) do nothing
returning account_id`,
[account.id, endsAt],
);
redirect(result.rowCount === 1 ? "/dashboard" : "/pricing?trial=used");
}The primary key does the real work. Code that reads first and writes second leaves a gap that two requests landing together can both get through. Here the second insert returns no rows. Your driver's rowCount and your database's conflict clause may differ.
Then count every run the same way, with one update that adds 1 only while runs_used is under 500 and the trial hasn't ended, before you pay for the work.
Next.js's own documentation says Server Actions are reachable by direct POST request, and that you shouldn't rely on proxy, layout or page checks alone.
| Place in your app | Fine for | Why the limit can't live there |
|---|---|---|
| Client Component or browser storage | Showing days left | The browser belongs to the user |
proxy.ts (formerly middleware) | A quick redirect with no session | Not meant for slow data fetching or full authorization |
| Layout or page | A trial banner | Layouts don't rerender on navigation, and actions can be called without loading the page |
| Server Action or Route Handler | The limit itself | It can. Check the session inside each one |
Where the server-side limit breaks
Everything above hangs on one ID. Follow what happens when the ID is new.
Twenty accounts get 10,000 runs (20 × 500). That's $300 (10,000 × $0.03), or about what six customers pay you in a month ($300 ÷ $49 = 6.1). No query in your app is wrong. Your metering holds each account to exactly 500 runs, and the next account starts at zero.
The basic checks you'll try next, and how each one breaks
Email comes first, and it has quirks. Gmail ignores dots in personal addresses, so sam.lee@gmail.com and samlee@gmail.com reach one inbox, and so does sam.lee+anything@gmail.com. That's how dots and plus addressing work.
| Basic check | Catches | Misses | Wrongly blocks | Cost to keep working |
|---|---|---|---|---|
| Email verification | Typos and dead addresses | Any second working inbox | People whose code lands in spam | Sending and deliverability work |
| Unique emails | The same address twice | Every different address | Almost nobody | Very little |
| Disposable-domain blocks | Services on your list | Newer domains | Privacy forwarding users | A list someone maintains forever |
| Gmail dots and plus addressing | One inbox written several ways | A second real mailbox | People who sort their mail with plus addresses | Upkeep as mail services change |
| CAPTCHA | Basic scripts | People signing up by hand | Screen reader users | Fees and lost signups |
| Phone or card requirement | Casual repeat signups | Anyone with another number or card | Students, people without a reliable mobile number | Text fees, fewer trials started |
| One per IP address | Repeats on one connection | Any other network | Offices, campuses, households | Exceptions and tickets |
| VPN blocks | Listed ranges | Everything unlisted | Staff on company VPNs | Another list to maintain |
| Rate limits | Bursts from one source | 20 accounts each under the limit | Real users in a busy hour | A shared store and tuning |
| Usage caps | One account overrunning | The next account's fresh cap | Honest users at the cap | Deciding when your product stops |
| Shorter trials or fewer runs | Value per account | 100 runs instead of 500 just needs 100 accounts, not 20 | Every honest user | Fewer people reach paying |
| Manual review | What a person can spot | Anything overnight | Whoever looks odd | At one minute each, 1,240 trials is about 21 hours |
Rate limits have a Next.js catch. proxy.ts looks like their home, but the docs warn against relying on shared modules or globals there, so you need a shared store, which is one more thing to run.
Stack the rest and your launch page asks for a verified email, a puzzle, a phone number and a card. Say that costs you a quarter of your real trials, 215 of your 860 people. At a 5% trial-to-paid rate (both figures illustrative), that's about 11 customers, or $539 a month at $49 each, and nobody emails to tell you.
What to put in place this week
Ship the claim table and one startTrial path, and meter every paid call on the server.
Give trial traffic its own budget and a hard spending cap. Some provider settings only send an alert, so read yours closely.
Hold expensive work until the email is confirmed, so an account that never confirms costs you one email.
Decide what a no looks like. Offer a paid plan and a way to reach you, because some people you turn away will be real.
That setup answers one question: has this account had a trial? What cost you $5,700 was a different question, whether a claim from a brand new account is a repeat, and nothing you can add to trial_claims answers it.
The question your table can't answer
Does this claim look like a repeat? AbuseZero exists to answer that, and the fixes that just broke are where it starts. Your email rules only go so far and your domain list goes stale, while AbuseZero checks mailbox aliases, disposable domains and mail routing. Your one-per-IP limit lands on a whole office, and AbuseZero sees beyond an IP address with VPN, hosting, network reputation, Tor and proxy intelligence. A new account_id has no row in your table, yet AbuseZero recognizes repeat devices across new accounts, even when email addresses keep changing. Creating a fresh account isn't enough to erase previous activity. AbuseZero puts 140,000+ signals through multi-layer AI risk analysis, which detects linked claims and flags abuse that single checks miss. There's also a proprietary algorithm, with AI that checks the claim again. You don't have to build your own abuse prevention system.
In your app it's one API call from startTrial, before the insert, through the Node.js SDK. You get a clear allow or deny, under rules you control. Observe mode shows you what would be denied before anyone is blocked. Your trial_claims table stays, because your app still grants and meters the trial.
Frequently asked questions
Where should a free trial limit live in Next.js?
In a server-only function called from each Server Action and Route Handler that grants or spends trial usage. Proxy, layouts and pages are fine for redirects and banners.
Does a unique email stop repeat free trials?
It stops the same address twice. See how to stop users signing up for a free trial again with a new email.
How do I allow one trial per person instead of per account?
Your own records can only tell you about accounts, so decide what your limit should be first. An AbuseZero evaluation then returns allow or deny each time a trial is claimed, under the rules you set.
Protect the next launch before it starts
Start with Builder
Pay as you go. Protect your first trial today.
See pricing
Builder, Pro, Scale and Enterprise.
Talk to us about Enterprise
High volumes and custom terms.