9 Replies
supbase client:
calling the query from next.js router handler:
i tried multiple methods from online and llms nothing helped so dropped here if anyone can please
Are you sure you have a user session there? Usually right after a signup call there is no user session as they have not confirmed yet. (There is a user object but not a session)
Also you have to meet select RLS on profiles for those policies you show to work.
1. i have turned off the confirmation mail thing
2. i have posted the complete rls policy above could you please check
I looked at it and pointed out one thing.
You have to meet select on profiles too.
oops sorry lemme check
Now it makes sense, I guess.
My signup flow is:
→ Supabase creates the user
→ Then I create a new row in the business table using auth.id
→ Then i create a new row in the profiles table using auth.id and business.id
The issue is that the business table needs profiles.business_id, which hasn’t been created yet. So the SELECT query isn’t able to execute properly and returns null.
But my question is: since I’m using the service role key, shouldn’t the RLS policies be bypassed?
Not if you use the same client to signup a user. The user session takes over. Also you should never use a service_role key on a browser, or really bother with a client that will have a signed in user.
Why don't you create your profile table with an auth.users trigger. That is what most do.
Yeah, but the trigger only knows the new user's ID. It has no way of knowing the businessName, ownerName, or phoneNumber that the user just entered in the signup form. I need that data to correctly create the business and profile records, so I skipped that option and went with this method instead.
idk i was right but correct me if im wrong please.
About what.
I have no idea how or when you get your business id from the user. If you are only using signup and not OAuth then you can always pass that data in with the data option on signUp and the auth.users trigger function can get the data and set up any table rows needed.
Otherwise you would need to do operations serverside, edge functions, or rpc call to security definer function if you have to bypass RLS.
changed the logic of RLS policy now working as expected!
thank you so much for your insights really helped to solve the problem
also added triggers 🙂