Protect client-side table access
A browser or mobile client queries Neon through the Data API.
Neon · Const
Neon RLS uses PostgreSQL Row-Level Security to restrict table rows according to the authenticated user. Tables exposed through the Neon Data API must have RLS enabled and policies configured.
Neon RLS uses PostgreSQL row-level security to decide which rows a user may access. Enable RLS on each table exposed through the Data API, then define policies that use auth.user_id() to compare the row owner with the authenticated user.
ALTER TABLE table_name ENABLE ROW LEVEL SECURITY;
CREATE POLICY policy_name ON table_name USING (condition);-- Enable RLS and allow users to access only their own rows
ALTER TABLE notes ENABLE ROW LEVEL SECURITY;
CREATE POLICY notes_owner_policy ON notes
USING (user_id = auth.user_id());This enables RLS for notes and filters rows by the authenticated user's ID.
A browser or mobile client queries Neon through the Data API.
Several users share a table but must see only their own records.
A multi-tenant application stores tenant data in shared tables.
RLS is PostgreSQL's per-row access-control feature. In Neon, policies determine which rows are available to the current user, and Data API tables must have RLS enabled.
Follow-up: What must be added after enabling RLS? Create policies that express the permitted access, commonly using auth.user_id() to match the row's owner.
The policy uses auth.user_id() to obtain the authenticated user's identifier and compares it with data in the row. Rows whose policy condition is not satisfied are not available through that policy.
Follow-up: How would you support multiple tenants? Store a tenant identifier on each protected row and write policy conditions that compare it with authenticated tenant context.
The Neon Data API exposes database tables through a REST interface, so its tables must be protected with PostgreSQL privileges and RLS policies. RLS controls which individual rows the user can access.
Follow-up: What should be checked if access is unexpectedly unrestricted? Verify that RLS is enabled, policies are present, and the connection does not use a role that bypasses RLS.
PostgreSQL Row-Level SecurityNeon Data APIauth.user_id()RLS policies