Next.js SSR and row-level security
See original GitHub issueFirst off, thanks the team for this awesome library!
I’m using magic link authentication. I have found that even after a user has been identified, and if row-level security is enabled (to allow only a user with a specific email address), then inside getServerSideProps
the data cannot be fetched using supabase client, i.e. this code is returning empty data and null error (and the user has been identified)
const { user } = await supabase.auth.api.getUserByCookie(req);
if (!user) {
return { props: {}, redirect: { destination: "/" } };
}
const { data, error } = await supabase.from(...)
...
Hope you will help me see what’s going on.
Thanks!!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to use row level security in a Next.js and Supabase app
Next.js is the React framework for production by Vercel. ... How to use row level security in a Next.js and Supabase app.
Read more >Advanced Features: Next.js Compiler
The Next. js Compiler, written in Rust using SWC, allows Next. js to transform and minify your JavaScript code for production. This replaces...
Read more >Make User State Globally Accessible in Next.js with React ...
Using React Context, we can create global variables that are available throughout our Next.js application. In this video, we create a useUser hook...
Read more >Next.js Crash Course - SSG, SSR, API Routes, and more
In this short course we will learn about Next. js (the React Framework for Production). A framework that allows you to render a...
Read more >What is the point of SSR these days? #10437 - GitHub
Next.js is a hybrid framework. We will be recommending static and static site generation as a default. We already output .html files if...
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
@kiwicopple Thanks a lot, supabase team is awesome!
Just a short clarification: I did use
setAuthCookie
and that was why I was able to callgetUserByCookie
insidegetServerSideProps
. As I commented above, I could then getuser
, but the following call to fetch the tables (i.g.const { data, error } = await supabase.from("")...
) just return null data and undefined error when low-level security is set up.I’m checking this ‘token’ that you just made available and will let you know. Thanks again!
I may not be understanding your question properly, so if not feel free to comment back
I assume that
getServerSideProps
is your own route? Ideally when you first authenticate the user you call setAuthCookie in a server route. This will create a cookie, which is then passed with all network requests.After that, you can pull the user’s details out of the cookie - you don’t need to store
access_token
anywhere. I just updated the latest version of supabase-js to support getting the token directly from the cookie. It should work like this:I’ll close this one for now, but if there is a bug that you feel needs fixing just let me know and I’ll reopen