-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth issue, anon working #19
Comments
Would really appreciate this as well. I have printed out the RESTful request statement in the
|
@YancyFrySr once you have logged in and have a user's access_token, you can do
and then it will add that as the header |
Is this the official solution? I was also under the impression that we should be able to pass auth information through context, or create a session-ed client somehow. This is a bit problematic because for example the Storage pkg does not have a AddHeader method, and I'm suspecting the problem I'm facing right now is because of that. File uploads for anon work, but not for authenticated, likely because the Storage stuff doesn't add auth info |
Okay got it working. Reading through the code, there's a comment above apiKey within the client that it can be a client key as well:
So we have to create a user scoped client that uses client API key:
/EDIT: okay doing that is giving me "invalid api_key" errors when using DB actions. I ran out of time for debugging so just created 2 clients, one for upload and one for db..
|
Also wasted a ton of time on this - apparently it works on the local supabase docker stack but for production we have to set the apiKey separately. In case someone else runs into this, apparently what's missing is the Explicitly adding the anon key using like this works: userScopedDB := supa.CreateClient(URL, userAccessToken, false).DB
userScopedDB.AddHeader("apikey", anonKey) |
@urjitbhatia would you mind sharing the full snippet of what worked for you, spent close to 8hrs debugging before finally seeing this issues open here too, when you declared the new client how did you use it to query the db |
@saintmalik sure, happy to help. With either of the following approaches, you will get a user scoped DB connection which will honour the RLS policies of your supabase tables. Situation 1If you are using the postgrest client: Using debug = false
This makes it work in production. The problem is that it works without that extra explicitly set header locally so it's hard to debug. Using debug = true
This works locally as well as in production but I am not sure if it's the best approach setting debug to true in production. Situation 2If you are using the native postgres sql framework:
You get the userId from the JWT token...FWIW, I ended up using the native pgx client rather than the postgrest client since it has better sql support and opens up the ability to use ORMs etc |
Hi all, I may be doing something stupid here so please forgive me.
When i run a sign in, how do i then use that logged in user to perform requests against the DB?
My query is working with RLS allowing anon however when RLS is enabled to only allow authenticated users I don't get a response.
I've tried multiple ways of enabling auth only for SELECT on the table. for example:
My call to signIn does also respond with a user token.
In supabase logs it appears that no auth header is added to the requests:
Any help would be appreciated
The text was updated successfully, but these errors were encountered: