"session_user" value is inconsistent between hosted and local versions
See original GitHub issueBug report
I have a psql function which references the “session_user” variable to differentiate between being called by an authenticated user and a trigger. The function is “is_claims_admin()” from this guide;
I noticed my rls policies were passing on local and failing on dev. After troubleshooting this on discord, I noticed that my hosted production isntance is returning “authenticator” for the session_user value while my local dev is returning “postgres”.
Steps to reproduce:
- Create a local supabase instance:
supabase init
(for local) - Create a function which can be used to get the value of session_user with an authenticated session:
CREATE OR REPLACE FUNCTION public.sesh()
RETURNS text
LANGUAGE plpgsql
AS $function$
BEGIN
return session_user;
END;
$function$
- Create a user on the supabase instance:
curl -X POST 'http://localhost:54321/auth/v1/signup' \
-H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs" \
-H "Content-Type: application/json" \
-d '{
"email": "someone@email.com",
"password": "eORzCgpVRYTyIVmipLnY"
}'
- Sign in as the user and get the jwt:
curl -X POST 'http://localhost:54321/auth/v1/token?grant_type=password' \
-H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs" \
-H "Content-Type: application/json" \
-d '{
"email": "someone@email.com",
"password": "eORzCgpVRYTyIVmipLnY"
}'
- Issue a rest api call with the jwt and call the function:
curl -X POST 'http://localhost:54321/rest/v1/rpc/sesh' \
-H "Content-Type: application/json" \
-H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs" \
-H "Authorization: Bearer ${USER_JWT_HERE}"
- Observe that the output is “postgres”
- Repeat steps with a hosted isntance of supabase
- Observer that the output is “authenticator”
Expected behavior
Supabase hosted and local versions should behave the same in order for local dev environments to be useful.
System information
- OS: macOS 13.0.1
- Version of supabase-cli: 1.14.3
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
PHP Session discrepancy between development (localhost ...
This works perfectly on my local machine. When I upload to my hosted server (happens to be Google Cloud) and adjust the client...
Read more >sessionid iRules command may return inconsistent session ID ...
The SSL::sessionid iRules command may return inconsistent session ID values. This issue occurs when all of the following conditions are met:.
Read more >Consistency levels in Azure Cosmos DB - Microsoft Learn
Azure Cosmos DB has five consistency levels to help balance eventual consistency, availability, and latency trade-offs.
Read more >Session Management - Amazon AWS
A centralized session management data store provides consistent user ... ways to manage user sessions including storing those sessions locally to the node ......
Read more >What is Session Stickiness | Pros and Cons of Using ... - Imperva
Session stickiness is a process that creates an affinity between a user and ... that users are never routed to a server after...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@barbinbrad Well you can sort of workaround it by changing the $POSTGRES_USER env variable on the db container but that’s not particularly streamlined vs running the supabase cli
Thank you!