Thomas Osayi

November 22, 2026 · 9 min read · Thomas Osayi

How to add an admin dashboard to a Lovable app safely

Roles, protected routes, server-side checks and Supabase RLS policies for admins: how to add an admin dashboard to a Lovable app without exposing every user record.

Most apps reach the point where the founder needs to see everything: all users, all orders, all bookings, plus buttons to refund, ban or edit. So they ask Lovable for an admin dashboard, get a good-looking page in a few minutes, and ship it. The page works. The problem is usually what it is allowed to read, and who else can read it too.

This is how I add an admin dashboard to a Lovable app so that it is useful for the team and closed to everyone else.

How do I add an admin dashboard to a Lovable app?

Define roles in the database, protect the admin routes in the interface, and enforce every admin permission on the server through RLS policies and edge functions.

Those are three layers, and each does a different job:

  • The roles table decides who is an admin. It is the source of truth.
  • The protected route decides which screens appear. It is convenience, not security.
  • RLS policies and server functions decide what data can actually be read or changed. This is the security.

Lovable apps typically talk to Supabase directly from the browser using the public anon key. That is fine by design, because RLS policies decide what each signed-in user may do. It also means anything your admin page can fetch, any signed-in user can try to fetch with the same key and their own token, using nothing but the browser console. If the policies do not distinguish admins from users, the admin page has effectively published your data.

I wrote about the general risk in "Is your Lovable or Bolt app leaking data? Check Supabase row level security." An admin dashboard is the place where that risk is highest, because admin queries are, by definition, the ones that read other people's records.

Where should admin roles be stored?

Store roles in a dedicated table, such as user_roles, that users can read for themselves but never insert into or update.

The mistake I see most in AI-built apps is a role column on the profiles table, together with a policy that lets users update their own profile. That combination lets any user make themselves an admin with one request. The interface never offers the option, but the API does not care about the interface.

Supabase's own guide on custom claims and role-based access control uses a cleaner pattern:

  • An enum type, app_role, listing the roles.
  • A user_roles table mapping each user_id to a role, one row per user and role.
  • Optionally, a role_permissions table mapping each role to specific permissions.
  • A custom access token hook, custom_access_token_hook, that adds a user_role claim to the JWT when a session token is issued. You enable it under Authentication, then Hooks, in the dashboard.
  • An authorize function that reads the claim from auth.jwt() and checks it against role_permissions.

Simpler apps can skip the permissions table and the hook, and write a small security definer function, for example is_admin(), that checks user_roles for the current auth.uid(). Either way, only an existing admin or a migration should be able to write to the roles table.

How do I protect admin routes in a Lovable app?

Wrap the admin routes in a guard component that checks the user's role and redirects everyone else, and treat it as a user experience feature, not a lock.

In a React app built by Lovable, that usually means a component around the admin routes that waits for the session, reads the role (from the JWT claim or a query to user_roles), shows a loader while checking, and redirects non-admins to the home page. Ask Lovable for it explicitly, and then read the code.

Things to check in what gets generated:

  • It waits for the session to load before deciding. Otherwise admins get bounced on refresh.
  • It does not read the role from local storage or a URL parameter, which anyone can edit.
  • Every admin route sits inside the guard, including nested pages like /admin/users/123.
  • The admin navigation link is hidden for non-admins, which avoids confusion, not attacks.

Then assume the guard is bypassed, because it can be. A user can open the bundle, find the admin queries and run them from the console. Everything after this section is what stops that.

How do I write RLS policies for admins?

Add admin policies alongside the normal owner policies, so a row is readable if it belongs to the user or if the user is an admin.

A typical orders table already has a policy like "users can select their own orders" using auth.uid() = user_id. For the dashboard, add a second select policy that allows the row when is_admin() returns true, or when authorize('orders.read') does if you use the permissions pattern. Postgres combines permissive policies with OR, so normal users keep seeing their own rows and admins see all of them.

Rules I follow:

  • Write separate policies for select, insert, update and delete. An admin who needs to read orders does not automatically need to delete them.
  • Wrap the function call in a select, as Supabase's guide does, so Postgres evaluates it once per query rather than once per row.
  • Make the role-check function security definer with a fixed search_path, so it can read user_roles without opening that table to everyone.
  • Never write a policy that checks a value the client sends, like a role field in the request body.
  • After adding policies, sign in as a normal user and run the admin query from the browser console. It should return only that user's rows.

When does admin logic need an edge function?

Use an edge function whenever an admin action needs powers a signed-in user should never have, such as the service role key, a Stripe secret or another user's auth record.

Examples: issuing a refund, deleting a user's account, changing someone's email, sending an email on behalf of the business or exporting all records to CSV. These need secrets or bypass RLS entirely, so they cannot run in the browser.

The pattern inside the function:

  • Read the caller's JWT from the Authorization header and verify it with Supabase.
  • Check the caller is an admin by querying user_roles, using the caller's identity, not a flag in the request.
  • Only then create a client with the service role key and perform the action.
  • Write an audit row: who did what, to which record, and when.

The service role key must live only in the edge function's secrets. If it ever appeared in front-end code or a public repo, rotate it. Admin tools that skip the first two steps are the same as giving every user the service role key.

How should I design roles if I have more than admin and user?

List every role and every kind of record, then decide read, write or nothing for each pair before building screens.

Guardian MindCare, a therapy practice platform I built, has five roles: therapists, supervisors, trainees, clients and admins. Each has its own portal and sees only what it should. A trainee should not see what a supervisor sees, and neither should see what an admin sees. That platform runs on Firebase, so the checks live in security rules that compare the user's role and ID with each record, but the planning step is the same in Supabase: the permissions table comes first, and the screens follow from it.

The Guardian MindCare homepage with its provider search; behind it, the platform has separate portals for five roles.
The Guardian MindCare homepage with its provider search; behind it, the platform has separate portals for five roles.

For most Lovable apps, two or three roles are enough: admin, staff and user. Resist adding roles before you need them. Each role multiplies the policies to write and the combinations to test. "Roles and permissions in a SaaS app: a practical guide for founders" goes deeper on modeling roles, including when to scope them to an organization.

What should the admin dashboard actually include?

Start with the few views and actions the team uses every week, and add the rest when someone asks for them twice.

A useful first version for a typical app:

  • A users list with search, sign-up date, plan and status.
  • A record list for your main object, such as orders, bookings or submissions, with filters and a detail view.
  • Two or three key numbers on the home view, such as new sign-ups this week, active subscriptions and open support items.
  • The handful of actions that currently require you to open the Supabase dashboard, such as marking a booking as refunded or disabling an account.
  • An audit log view, even a simple one.

Paginate every list. AI-generated admin pages often fetch every row and filter in the browser. That works with fifty rows and falls over with fifty thousand, and it also pulls every record over the network to the admin's laptop.

What are the most common mistakes in AI-built admin panels?

The most common mistakes are client-only checks, a user-editable role field, and the service role key in front-end code.

The full list I check when someone hands me an admin panel:

  • Admin check done only in the route guard, with no RLS or server check behind it.
  • Role stored on profiles with a self-update policy.
  • An RLS policy of "true" for select on a table, added to make the admin page load.
  • The service role key in a Vite environment variable with the VITE_ prefix, which ships it to the browser.
  • Admin email addresses hardcoded in the front end as the only check.
  • No audit trail for destructive actions.
  • Unbounded queries that load the whole table.

Each of these is quick to fix once found. Finding them is the part that takes a careful read.

How do I test the admin dashboard before launch?

Create one test account per role, then try to reach every admin screen and every admin query from the non-admin accounts.

My routine:

  • Sign in as a normal user. Visit /admin and nested admin URLs directly. You should be redirected.
  • In the browser console, run the same Supabase queries the admin page runs. You should get only your own rows, or nothing.
  • Try to update your own role row. It should fail.
  • Call each admin edge function with a normal user's token. It should return 401 or 403.
  • Sign in as an admin and confirm everything works, including on a hard refresh.

If you work in Lovable with GitHub sync on, make these changes on a branch and test there before merging. "How to hand off your AI-built app to a developer" explains how to share access when you want someone else to run this check.

The bottom line

An admin dashboard in a Lovable app is three things: a roles table users cannot edit, route guards for convenience, and RLS policies plus edge functions that enforce admin access on the server. The screens are the easy part, and Lovable will generate them well. The policies are where the risk sits, so read them, test them as every role, and keep secrets out of the browser.

If you want it done for you, my Fix Plus Features package starts at $200 for up to three fixes plus one small feature, such as a first admin view with proper policies. Apps that need many roles and full admin tooling fit my Full SaaS Platform package from $3,000.

Questions, answered in one line

Can I just hide the admin page from normal users?

No, hiding the page stops nobody, because the Supabase API is public and a user can query tables directly with their own token.

Where should I store user roles in Supabase?

Store them in a separate table such as user_roles with RLS that lets users read but never insert or update their own role.

Should the admin dashboard use the service role key?

Only inside server code such as an edge function that first checks the caller is an admin, and never in the browser, because the service role key bypasses RLS.

Can Lovable build the admin dashboard for me?

Lovable can generate the screens quickly, but review the generated policies and role checks by hand, because that is where AI-built admin panels most often leak data.

How much does it cost to have an admin dashboard added?

Thomas Osayi adds a small admin feature alongside up to three fixes from $200, and multi-role platforms with admin tools start at $3,000.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service