Add auth without painting yourself into a corner
Email, social, SSO — pick the one that fits, and make sure the access rules can grow with you.
What you'll have at the end
An auth setup that handles today's users and tomorrow's roles without a rewrite. Sign-in works on the first try, sessions don't randomly die, the access rules are written down somewhere a non-engineer can read, and you can add SSO or a new user type in a week instead of a quarter.
01
Who this is for
- Builders past the prototype stage who've been getting by with 'everyone's an admin'
- Teams about to onboard their first paying customers, contractors, or partner users
- Anyone whose app is going to need 'admin vs member vs viewer' soon and wants to set it up once, properly
02
How to frame the idea
Auth has two parts and most people only think about the first one. The easy part: how does someone prove they are who they say they are (email + password, Google, Microsoft, SSO). The hard part — and the one that paints you into corners — is what they're allowed to do once they're in (roles, permissions, scoping by tenant, audit trail). Pick the sign-in method that fits your user (consumers love Google; enterprises require SSO; internal tools tolerate email/password). Then design the access model on paper BEFORE you write a line of code. The access model is the part that's expensive to change later.
03
What people actually build
Consumer app: email + Google
B2C users want one-click sign-in with Google (or Apple on iOS) and an email/password fallback. Magic links work great for low-stakes apps. Skip 'create a username' — email is the username.
B2B app: email + Google + Microsoft, with SSO on the roadmap
Self-serve customers sign in with email or Google/Microsoft. Enterprise customers will eventually require SAML/OIDC SSO via Okta, Azure AD, Google Workspace. Pick an auth provider that handles SSO so you don't have to migrate at the worst possible moment.
Internal tool: SSO only
Everyone at your company has a Google Workspace or Microsoft account. Just use that. No new passwords, no offboarding nightmare, no shared logins. Restrict by domain.
Multi-tenant SaaS: users belong to organizations
A user can be in multiple orgs with different roles in each. Permissions are scoped to (user, org, role). This is where naive auth designs break — plan for it on day one if you're going B2B.
04
Tool choices, honestly
Lovable Cloud (built-in auth)
Default for Lovable projects. Email, social, magic links, sessions, and row-level access policies all in one place. Best when your app and your auth live in the same project.
Clerk / Auth0 / WorkOS
You need SSO, SCIM provisioning, or polished pre-built UI components for sign-in, MFA, and account management. WorkOS is especially good when SSO is part of your enterprise pitch.
Supabase Auth (under Lovable Cloud)
You want JWT-based auth with row-level security in the database. Strong default for apps where 'who can see this row' is the core access question.
A separate roles & permissions table
Always. Never store the user's role on the user/profile table — that's a privilege-escalation footgun. A separate user_roles table (with a security-definer function to check membership) is the pattern that survives every refactor.
05
Prompts you can lift
Design the access model on paper first
Before I add auth code, help me design the access model. My app is <one paragraph>. The types of users are <list>. For each user type, tell me: what they can see, what they can create, what they can edit, what they can delete, and whether scope is per-user, per-organization, or global. Output a single table I can paste into the README. Reject 'admin' as a catch-all — make me name the specific powers.
Pick the sign-in methods that fit
Help me pick sign-in methods. My users are <description>. They sign in on <web/mobile/both>. They are <consumer/B2B/internal>. Recommend the 1-3 methods that fit, the ones I should skip, and the ones I should plan to add later (especially SSO). Tell me what 'good defaults' look like for password rules, session length, and account recovery.
Implement roles with the safe pattern
Add roles to my app. Create a separate user_roles table (NOT a column on profiles), enums for the roles <list>, RLS policies that use a security-definer has_role() function to avoid recursive policy checks, and seed-data for at least one admin. Show me the exact migration. After it runs, walk me through how I'd promote a user to admin by hand if I needed to.
Plan for SSO before you need it
I don't need SSO today, but I will. Walk me through what to do now so adding SAML/OIDC later isn't a rewrite. Specifically: how should I model 'organization,' 'membership,' and 'identity provider' so the existing email-password users keep working when an enterprise customer turns on SSO for their org? What should I name things to avoid renaming columns later?
Audit the auth-adjacent corners
Walk through every auth-adjacent surface in my app: sign-up, sign-in, password reset, email change, account deletion, invitations, session timeout, sign-out everywhere, MFA, audit log. For each one, tell me what good looks like, what I have today, and what's missing. Prioritize the gaps by 'will hurt me with real users' vs 'nice to have.'
Save and reuse these prompts in PromptlyDo™ with your favorite AI.
- Install the PromptlyDo™ browser extension
- Sign in or create a free account
- Right-click any prompt above and save it to PromptlyDo™
06
What tends to break
- Storing the user's role on the profile/user table. The first time someone exploits 'PATCH /profile { role: admin }', you'll wish you'd used a separate table.
- Anonymous sign-ups left enabled, then accidentally used as 'guest mode.' Anonymous users carry a real auth identity and confuse every analytics and permissions query later.
- Building roles before designing them — three weeks in you discover 'editor' actually means four different things to four different users.
- Sign-in works in dev but not in prod because redirect URLs / allowed origins weren't configured. Always test sign-in in prod before you tell users about it.
- Magic links that expire in 5 minutes for users who don't open email for hours.
- No way to sign a user out of all sessions when they say their account is compromised. By the time you need this, building it is panic work.
- Forgetting that 'remove user from org' should also remove their access on the next request — not 24 hours later when the JWT expires.
- Letting one Google account create an account, then a 'Sign in with email' account, then a 'Sign in with Microsoft' account — all for the same person. Account linking by verified email solves this if you build it early.
07
What AI forgot to ask you
- Are users individuals, or do they belong to organizations? If organizations, that changes literally every permissions check.
- Will you ever need SSO? If 'maybe in 18 months,' build the data model to support it now even if the UI comes later.
- What's the recovery story when a user loses access to their email? 'Email me' is fine until it isn't.
- Do you need MFA, and for which roles? Often required for admin even when optional for end users.
- What's logged for audit — sign-ins, role changes, sensitive actions? Compliance asks for this; build it before they do.
- How do invitations work? Pre-created accounts vs invitation tokens vs 'just share the link' have very different security profiles.
- What's the offboarding flow when an employee leaves a customer org? Manual revoke, SCIM, or 'they'll figure it out'?
08
Before real users see it
- There's a separate user_roles table; no role data lives on the profile/user table.
- RLS policies use a security-definer function (not direct table reads) so they don't recurse.
- I can sign up, sign in, reset password, change email, sign out of all sessions, and delete my account — and I've done each at least once in prod.
- Sign-in redirect URLs are configured for every environment (local, preview, prod). I tested the published URL, not just dev.
- An admin promotion requires explicit action (DB row, admin UI), not a self-serve toggle.
- Every sensitive action is in an audit log with timestamp, actor, and what changed.
- Removing a user from a team / org takes effect on the next request, not the next day.
- I tried to break it: signed in as a low-privilege user and confirmed I cannot reach admin pages, admin APIs, or admin data.
09
Questions to sit with
- 1.Who are my users in 18 months — same as today, or do I expect orgs, partners, contractors, or enterprise SSO? That answer should drive the data model now.
- 2.What's the worst-case if the wrong user sees data they shouldn't — embarrassing, expensive, or a breach notification? That sets how paranoid the model needs to be.
- 3.Am I willing to pay for an auth provider (Clerk, WorkOS, Auth0) to skip building MFA, SSO, and SCIM myself? For B2B SaaS, the answer is almost always yes.
- 4.Who's the 'break glass' admin if I lose access to my own account, and have I actually tested that path?
- 5.Where do my roles get documented so a new teammate can read them without reading code?
Ready to app it?
Take this path into your tool of choice — and when you finish (or get stuck), share what you learned so the next builder doesn't reinvent it.
