How to Add User Roles and Permissions
Admin, editor and member roles done safely — stored separately from user profiles so they cannot be escalated.
Published 24 Aug 2026 · Tested with Lovable as of 24 Aug 2026

Overview
Roles decide what a signed-in user is allowed to do. Where you store them determines whether they can be faked.
Beginner explanation: If a user can edit their own profile, and their role lives on their profile, they can make themselves an admin. That is the whole problem.
Technical explanation: Store roles in a dedicated table keyed by user, and check them through a security-definer function used inside your access rules. Never read a role from client-side storage.
Steps
- Create a roles table with a user reference and a role value.
- Create a function that checks whether a user has a role.
- Use that function inside your access rules.
- Add an admin-only area that calls the same check server-side.
- Test with a non-admin account.
:::tip Check the role again inside every privileged server action. A hidden menu item is not a permission system. :::
What to check afterwards
- A normal user cannot reach admin pages or admin data
- Role changes take effect on the next request
- Privileged actions fail cleanly for non-admins
Common problems
- A role column on the profiles table. Users can usually edit their own profile.
- Role stored in browser storage. Trivially edited.
- UI-only checks. The endpoint stays open.
Where people get stuck
If you have followed the steps and the result still is not right, the fastest path is usually to describe the exact behaviour you expected, the behaviour you got, and any error text, then ask for a fix in one focused follow-up prompt. If that loop is not converging, hand it over.
Prompts that pair with this guide
Add Authentication With Email and Google
Sign-up, sign-in, sign-out, session handling and protected routes in one pass.
Copy this prompt →Add Role-Based User Permissions
Creates a safe role system stored in its own table, with a role-check function used by your access rules and server actions.
Copy this prompt →Related guides
How to Create Protected Pages
Restrict routes to signed-in users properly — including the server-side check most AI-generated guards miss.
How to Add User Login to a Lovable Project
Sign-up, sign-in, sign-out and sessions — plus the settings people forget that break login on the live site.