CRM: Sales Rep Cannot See a Lead After It Is Unblocked
Problem: After removing the blocked field or status flag in CRM, the sales representative still does not see the record. This is a typical symptom of the Row-Level Security layer, incorrect permissions or discrepancies between the user token and the policy condition. Instead of just unlocking the record, you need to check the RLS policies in the database, assigning the record owner, mapping claims in the JWT token used by the application and whether there are additional filters on the API/ORM side. The following text leads through differential analysis, specific diagnostic steps and tests in the Supabase/Postgres environment and a list of typical traps to check.
How to Recognize Cause
Check that the RLS lead table is enabled (row security = on). If RLS disabled, the problem can lie on the application side or cache. If enabled, the next suspects are SELECT policy: the USING condition determines whether the line is visible and WITH CHECK decides on INSERT/UPDATE. Often the condition refers to claims jwt (auth.uid, roles) and changing the blocked flag does not affect the expr.
Examine token trading session and claims values (sub, roles, user id). A popular error is the mismatch of the owner's fields in the table (owner id) and claimu in the token (auth.uid or sub). Another common case is an outdated token after changing roles: JWT may still have an old role, so the row only meets USING for a new role.
Finally, check whether the intermediate layer API (REST, GraphQL, ORM) does not use additional filters (e.g. where: {signed to: currentUser }) or whether the client does not cache the results. Also transactions or no commit after a status change may make the change not visible for another connection.
Step by step solution
1. Confirm that RLS is enabled: in psql run SELECT remotesecurity FROM pg class WHERE relname='leads'; if true, continue; if false, check GRANT permissions and application logic.
2 . Log in as a sales representative in the context of the database (simulate JWT/SET ROLE). In Supabase, use policy test tool or in psql: SET LOCAL role = 'anon' is not enough – instead, run a query with the appropriate jwt claims or use RLS-tables test hardness. Read current setting('jwt.claims') if used.
3 . Read RLS policies: SELECT pol.polname, pol.polpermissive, pg get expr(pol.polqual, pol.polrelid) AS using, pg get expr(pol.polwithcheck, pol.polrelid) AS withcheck FROM pg policy pol JOIN pg class c ON polrelid=c.oid WHERE c.relname='leads'; Analyze USING and WITH CHECK expressions with respect to blocked field and owner id.
4 . Compare Owner id/assigned to in line with values in token: SELECT id, owner id, assigned to, blocked FROM leads WHERE id = <ilead>; then verify jwt.claims.sub and /or roles in token. If the values don't match, or the politics refer to another field, that's the reason.
5 . Check if the Token sales representative has current roles: in Supabase -> Authentication -> See JWT or syslogs. If the role has been changed recently, force a refresh of the token (re-login). Test: Make a request with a new token and compare the response.
6 . Test queries without RLS: temporarily disable RLS for this table or perform the query as superuser: SET ROLE postgres; SELECT ... FROM leads WHERE id=...; if the record is visible, cause is RLS policy; if still invisible, check application filtering or record status.
7 . Check the application layer: in backend logs identify SQL queries generated by ORM (e.g. Prisma, Hasura); make sure there is no extra WHE (assigned to = null) or pagination, and that there is no wrong projection that hides records.
How to see if the problem is gone
Test 1: Manual simulation — sign in as a sales representative, refresh the token, run SELECT id FROM leads WHERE id=< problem> in the context of this token (or use a supabase policy simulator). The result should change from empty to one line; if not, check the USING expression.
Test 2: superuser bypass — perform SELECT as superuser (SET ROLE postgres) to confirm that the record exists and the field blocked set correctly. If the superuser sees the record, the error concerns RLS/policy/claims; if he can't see, the data or transaction side issue.
What to do
Do not assume that the blocked field photo removes other policy conditions — USING policy can check assigned to or related status; changing one field does not guarantee visibility.
Don’t just test with the admin account — the superuser always sees the record, it’s a false sense of solution. Test with real JWT sales representative or policy simulator.
Don’t forget about caches and tokens — no JWT refresh after changing roles or caching frontend answers can mask the repair effect.