General Understanding in next.js and supabase
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Hey all, I apprecate any understanding that can be given to me here. Im just playing around and learning next/supabase. I was running into a issue where my UI wouldnt show someone as logged in and thats because my function to validate in getUser would come back null. now the thing that fixed it is i moved the initalization of supabase within the method. instead at the the top level. but my 2nd query DOES work fine it seems. I wouldnt get back any errors, just Null.
This is probably just a Javascript thing. but why would the call to validate the user not work with the top level initalization and we had to init it within the function itself? I know its a broad question but maybe there some simple JS rules i need to know
This is probably just a Javascript thing. but why would the call to validate the user not work with the top level initalization and we had to init it within the function itself? I know its a broad question but maybe there some simple JS rules i need to know
1 Reply
Argentine hake
When you create a supabase client using the standard role, it checks for cookies to see if the user has authenticated. For that reason you need to create a new client with each request. The client includes that information in requests to the DB so the DB knows who is authenticated (if anyone), and how to apply Row Level Security Policies.