How do I create admin users?
Last checked 31 Aug 2026
Short answer
Add a `user_roles` table with an `admin` role, assign it to the specific user's ID, and check that role server-side (in RLS policies and any admin-only functions) rather than trusting a front-end flag.
The correct pattern
Never store "is this user an admin" as a boolean column on a profiles/users table — a user could potentially edit their own row. Instead:
- Create a separate
user_rolestable with columns likeuser_idandrole(e.g.admin,moderator,user). - Use a Postgres function (
has_role(user_id, role)) checked inside RLS policies to gate admin-only reads/writes. - Assign the admin role to a specific account by inserting a row — ask Lovable to do this for you, or do it via a one-off admin action once you're signed in as that user.
Set up a user_roles table with admin and user roles, and make my account (email: you@example.com) an admin.
How to promote a user to admin
- Sign up normally with the account you want to be admin.
- Ask Lovable: "Give the user with email you@example.com the admin role in user_roles."
- Lovable Cloud users don't have direct database dashboard access, so always go through Lovable's chat to run this kind of one-off data change rather than looking for a Supabase dashboard.
What usually goes wrong
- Putting
roleon the profile table, which a signed-in user can update via a normal profile-edit form, silently making themselves admin. - Checking the role only in the front end (hiding a button) without an RLS policy — the underlying data is still exposed to direct API calls.
- Forgetting that RLS policies must reference the
user_rolestable via asecurity definerfunction to avoid recursive policy checks.
Once roles exist, restricting pages by role is covered in how-do-i-prevent-normal-users-accessing-admin-pages.
Sources
Was this answer helpful?
Related questions
- AnswerHow do I add password reset?Ask Lovable to add a "forgot password" flow — it uses Lovable Cloud's authentication to email a reset link and lets the user set a new password.
- AnswerHow do I add login to Lovable?Ask Lovable to add authentication — it enables Lovable Cloud (if not already on), then generates sign-up/login pages and wires them to email, Google, or other providers.
- AnswerWhy does my app keep redirecting to login?This is almost always a session or route-guard bug: either the auth session isn't persisting, or a protected route checks auth state before it's loaded, so it bounces back to login even when signed in.
- AnswerHow do I add Google login?Ask Lovable to add Google sign-in — it can use Lovable's managed Google OAuth for a quick setup, or your own Google Cloud OAuth credentials if you need custom branding or scopes.
You might also need
- GuideHow to Create Protected PagesRestrict routes to signed-in users properly — including the server-side check most AI-generated guards miss.
- GuideHow to Add User Login to a Lovable ProjectSign-up, sign-in, sign-out and sessions — plus the settings people forget that break login on the live site.
- GuideHow to Add User Roles and PermissionsAdmin, editor and member roles done safely — stored separately from user profiles so they cannot be escalated.