Supabase · PostgreSQL
Never use user_metadata in Supabase RLS policies
Any signed-in user can edit their own user_metadata from the browser. A policy that reads a role or tenant from it lets users make themselves admin. Use app_metadata or a table instead.
Two kinds of metadata
- user_metadata (raw_user_meta_data in auth.users): profile data the user controls, such as a display name. Writable by the signed-in user.
- app_metadata (raw_app_meta_data): data your server controls, such as a plan or role. Only writable with the service role.
await supabase.auth.updateUser({ data: { role: "admin", org_id: "<someone else's org>" } });
await supabase.auth.refreshSession(); // the new claims are now in the JWTPolicies to replace
-- before: user-controlled
using ((auth.jwt() -> 'user_metadata' ->> 'role') = 'admin')
-- after: server-controlled claim
using ((auth.jwt() -> 'app_metadata' ->> 'role') = 'admin')
-- or: a table only your server writes
using (exists (select 1 from private.admins a where a.user_id = (select auth.uid())))Set app_metadata from server code with the service role (auth.admin.updateUserById), or add claims with Supabase's custom access token hook. Remember that claims in a JWT only change when the token is refreshed, so for permissions that must take effect immediately, a table lookup is the safer source.
Check it yourself
Search your migrations for user_metadata and raw_user_meta_data. The RLS simulator flags any policy that reads them as critical.
Simulate your RLS policies (free, in your browser)
Questions
Is it fine to read user_metadata in the UI?
Yes, for display: a name or avatar. Just never base an access decision on it, in a policy, an Edge Function or a server action.
What about the email in the JWT?
Comparing auth.jwt() ->> 'email' is safer than metadata, but emails can change and may not be verified. Prefer the user id.
Updated 18 November 2026 · by Psychevus