Auth for Vibe Coders: Use a Provider, Do Not Roll Your Own

· 10 min read ·
vibe-coding security authentication supabase

A man in a green sweater at his desk hands a big golden padlock to a small white robot, who carries it toward a friendly locksmith in an apron standing at a workshop door

Use a hosted auth provider (Supabase Auth, Clerk, Auth0, Firebase Auth) and let it own signup, login, password reset and sessions. Do not ask your AI tool to write them from scratch. A provider is not magic, though: it handles who someone is, and your app still has to handle what they are allowed to do.

That second half is where the damage happens. In February 2026, a researcher reported 16 vulnerabilities in a Lovable-hosted app that exposed 18,697 user records. The app used Supabase for sign-in, so login itself was not the problem. According to the researcher, the AI-written backend functions (Supabase remote procedure calls) had access control logic that was backwards: it blocked signed-in users and let anonymous visitors through. He said the mistake repeated across several critical functions. The company behind the platform said the app’s creator had skipped the pre-publish security scan’s recommendations. (That is the company’s account, and the researcher disputes where the responsibility sits.)

So there are two jobs.

Why not just let the AI write login?

It will. It will even look right: a form, a /login route, a hashed password, a token in a cookie. The trouble is how many separate things a real login system has to get right, and how quietly each one fails.

  • Password storage. Passwords need a slow, salted hash built for the job. A plain SHA-256 “hash” looks fine in a code review and falls to a graphics card. If your AI already wrote this part, check it against OWASP’s password cheat sheet, which names Argon2id (at least 19 MiB of memory, 2 iterations, 1 lane) first and bcrypt with a work factor of 10 or more second. bcrypt only reads the first 72 bytes of a password.
  • Reset and confirmation emails. These are secret links. Every detail matters: how long the token lives, whether it works twice, whether the link can be pointed at someone else’s domain. See password reset flows that do not leak accounts.
  • Session handling. Where the token lives, how it is revoked, what happens on logout. See sessions vs JWT.
  • Everything that happens around the form. Rate limits, error messages that do not reveal whether an email exists, leaked-password checks, MFA.

An AI tool optimizes for “login works on my screen”. Nothing in that goal makes it write the abuse case. You find out about the missing ones from an attacker.

What a provider actually does for you

You are not paying for a login form. You are borrowing a team that has already shipped and patched all of the list above, and that gets the next vulnerability report before you do.

Supabase AuthClerk
Free plan50,000 monthly active users50,000 monthly retained users per app
Counts a user whenthey are active that monththey come back at least 24 hours after signing up
Where users livea table in your own Postgreson Clerk’s side
Fits best whenyou already use Supabase for datayou want prebuilt sign-in screens and organizations

Both numbers are from the vendors’ pricing pages as of 6 December 2026 (Supabase, Clerk), and pricing changes, so look before you commit. Auth0 and Firebase Auth are also fine, and so is a library like Auth.js if you want the code in your repo. The wrong choice is login code nobody on your team can name the author of.

If your data is already in Supabase, using Supabase Auth is the boring and correct answer. Its users sit next to your data, and your row level security policies can read the signed-in user’s id directly.

Three things a provider does not do for you

1. It does not check permissions on your server code

A provider answers “who is this?”. Your code still has to answer “may this person do that?” on every request, on the server, not in the React component. Hiding the admin button is decoration. Anyone can call your API without ever loading your page. This is the bug behind the Lovable story above, and the same family as the one row level security exists to catch. The full picture is in authorization vs authentication.

2. The user can edit some of the fields you might trust

Supabase’s own docs carry a warning that is easy to miss: users can edit their own user_metadata, and Supabase Auth does not check what they put in it. If your AI stored role: "admin" or a tenant_id there and then used it in a policy, any signed-in user can make themselves an admin with one updateUser() call. Roles and tenant ids belong in app_metadata, which only a trusted server can set.

3. Server code can read a session without checking it

In server code, getSession() reads the session out of the cookie without revalidating it. Supabase’s docs say never to trust it inside server code. Use getClaims(), which verifies the token’s signature on every call, or getUser() when you need a fresh record from the Auth server. It is everywhere in older tutorials and examples, so it is the version AI tools tend to produce.

Four dashboard settings worth five minutes

Check these once. They are the settings AI tools never mention.

  1. Site URL and redirect URLs. The Site URL defaults to http://localhost:3000. Supabase says to change it to your production URL because confirmation emails and password resets use it. In production, list exact redirect URLs. Wildcards like ** are handy for preview deploys and a bad idea for the live site.
  2. Email confirmation. Keep it on. Supabase’s docs say it is on by default for hosted projects but off for self-hosted and local development, so an app moved between the two can quietly lose it. Without it, anyone can sign up with someone else’s email address.
  3. Password rules. Supabase says anything under 8 characters is not recommended. It documents leaked-password protection (it checks the Pwned Passwords list) only on the Pro plan and above. On the free plan you do not get that check, so the workaround is a longer minimum length, such as 12 or more, and telling users to use a password manager.
  4. Delete the test accounts you made while building, especially any with a weak password and extra permissions.

A prompt to paste into your AI tool

List every place in this app that checks whether a user is signed in or has a role. For each one, tell me: is the check running on the server or only in the browser? Which function does it call to identify the user (flag any use of getSession on the server)? Does it read a role or tenant id from user_metadata? Then show me, for each protected route or function, the exact request an anonymous visitor could send to call it directly. Do not change any code yet.

Read the answers with the second half of this post next to you. “Only in the browser” and “user_metadata” are both a stop sign.

The check an engineer does by hand

Take one request your signed-in app makes (DevTools, Network tab, right-click, Copy as cURL). Paste it into a terminal, or hand it to your AI tool and ask it to run it. Then run it again with the Authorization line deleted (on Supabase, keep the apikey line, which is public). Next, replay one as a normal signed-in user against an admin-only action. If you use Supabase, include direct calls to your database functions too: they are reachable at /rest/v1/rpc/<function_name>, and the Lovable case was about functions like these. Both should be refused or come back empty (usually a 401 or 403). If either one returns real data or changes something, you have the Lovable bug, and no provider would have saved you.

Turn the guard into a test

The hand check finds a bug once. A test keeps it from coming back the next time the AI rewrites that file. Write tests about behavior (what each kind of visitor gets back), not about how the code is built. A test that says “a normal user is refused” survives a rewrite and fails the day a later fix opens the door again. A test that checks which function got called does neither.

Test it over HTTP, the way an attacker would, not just as a function call. A guard that is correct but never wired to the route protects nothing. The file below starts a tiny stand-in server and sends real requests with and without a token. Put your real guard where the stand-in is (the logic matters, not the framework) and run it with Node 18 or newer: node --test.

const test = require("node:test");
const assert = require("node:assert");
const http = require("node:http");
// Paste your app's real guard here. This is the inverted one:
function canViewAdmin(user) {
if (user) return false; // BUG: blocks everyone who is signed in
return true;
}
// A tiny stand-in server. The bearer token picks who is calling, like a real session would.
const users = {
"token-normal": { id: "u1", app_metadata: {}, user_metadata: {} },
"token-admin": { id: "u2", app_metadata: { role: "admin" }, user_metadata: {} },
"token-sneaky": { id: "u3", app_metadata: {}, user_metadata: { role: "admin" } },
};
const server = http.createServer((req, res) => {
const token = (req.headers.authorization || "").replace("Bearer ", "");
const user = users[token] || null;
if (req.url === "/admin/users") {
res.statusCode = canViewAdmin(user) ? 200 : (user ? 403 : 401);
return res.end(res.statusCode === 200 ? "secret user list" : "no");
}
res.statusCode = 404; res.end();
});
let base;
test.before(() => new Promise(r => server.listen(0, () => { base = `http://127.0.0.1:${server.address().port}`; r(); })));
test.after(() => server.close());
const get = (token) => fetch(base + "/admin/users", { headers: token ? { authorization: "Bearer " + token } : {} });
test("anonymous visitors are refused", async () => {
const r = await get(null);
assert.ok([401, 403].includes(r.status));
assert.notEqual(await r.text(), "secret user list");
});
test("normal users are refused", async () => assert.ok([401, 403].includes((await get("token-normal")).status)));
test("real admins get the data", async () => {
const r = await get("token-admin");
assert.equal(r.status, 200);
assert.equal(await r.text(), "secret user list"); // sanity: the route exists and returns data
});
test("a role in user_metadata does not count", async () => assert.ok([401, 403].includes((await get("token-sneaky")).status)));

Run first with the inverted guard above. This is a real run, in a scratch folder with Node 22:

not ok 1 - anonymous visitors are refused
ok 2 - normal users are refused
not ok 3 - real admins get the data
ok 4 - a role in user_metadata does not count
# pass 2
# fail 2

The inverted guard fails two of the four tests, the same shape as the Lovable bug. Now replace the guard with return user?.app_metadata?.role === "admin"; and run it again:

ok 1 - anonymous visitors are refused
ok 2 - normal users are refused
ok 3 - real admins get the data
ok 4 - a role in user_metadata does not count
# pass 4
# fail 0

Test 3 also checks that the route returns data for a real admin. Without that, a missing route would answer 404 to everyone and look like a pass for the “refused” tests. Test 4 catches a guard that trusts user_metadata.

If your data lives in Supabase, the same rule belongs in the database too. A row level security policy can read the role from the token, for example (auth.jwt() -> 'app_metadata' ->> 'role') = 'admin'. The same rule matters most in database functions you call over /rest/v1/rpc/. Supabase’s functions docs warn that a security definer function runs with its creator’s privileges, that a function made in the Dashboard or a migration is owned by postgres (which bypasses row level security), and that any role can call it by default, including anon. So check the role inside the function, or prefer security invoker, which is the default. To test that, run the same four cases as the anon and authenticated roles, for instance in pgTAP. These tests use a plain function behind a stand-in server, not a live Supabase project, so they prove your logic and nothing about your dashboard settings or policies.

Auth is one of the things that breaks first when real users arrive. The launch checklist and the 20-minute security check cover the rest.

The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.

Comments