DEV Community

Discussion on: Magic Link Authentication and Route Controls with Supabase and Next.js

Collapse
 
alexverdag profile image
Alex Verdaguer • Edited

Hi Nader, I followed the tutorial and it works just fine.

I made a change and doesn't work as expected. Instead of using client side for the 1st page after following the magic link I'm using server side as you do in the protected route, the problem is the user always returns null.

My code:

export async function getServerSideProps({ req }) {
const { user } = await supabase.auth.api.getUserByCookie(req);
console.log("user detail:", user);

if (!user) {
return { props: {}, redirect: { destination: "/login" } };
}

return {
props: {},
};
}

Collapse
 
shlokm289 profile image
Shlok.

in the last section you'll have to pass user to props:
props: { user }