I need help with getting user server side in NextJ...
# help
a
I need help with getting user server side in NextJS, when redirected by auth provider. When logging in via Google provider, it redirects to dashboard page. The dashboard page is a protected route, rather than checking client side if user is logged in, I want to check server side. I know you have to set cookie but those solutions only work after logging in client side, I want to set cookie before it redirects to dashboard page.
Copy code
js
const handleGoogleAuth = () => {
  supabase.auth.signIn(
    {
      provider: 'google',
    },
    {
      redirectTo: 'https://foo.com/dashboard',
    },
  );
};
// ...

button.onclick = handleGoogleAuth // fire signIn

// ... route to Dashboard

// Dashboard page
const Dashboard () => {
   return <div><h1>Dashboard</h1></div>
}
export const getServerSideProps: GetServerSideProps = async ({ query, req }) => {
  // req.cookie is empty object
  const { user, token } = await supabase.auth.api.getUserByCookie(req);
  // user and token are null, but that's because req.cookie is empty object
  return {
    props: {},
  };
};
export default Dashboard
s
At the moment I don't think this is possible, my current workaround is to redirect to a loading page before redirecting to the dashboard. This way the client gets to send the request to set the cookie before the server tries to read it.