Good morning community, I have a question. I am de...
# javascript
p
Good morning community, I have a question. I am developing an application with Nextjs which I use Supabase as Backend. The login is done in the following way:
Copy code
ts
 const handleLogin = async () => {
    const { error } = await supabase.auth.signIn({provider: "github"});
    if (error) {
      alert(JSON.stringify(error));
    }
  };
and I get the user. But when I access a path protected with getServerSideProps:
Copy code
ts
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
  const { user } = await supabase.auth.api.getUserByCookie(req);
  if (!user) {
    return { props: {}, redirect: { destination: "/" } };
  }
  return { props: { user } };
};
the user is always null. My "pages/api/auth.ts":
Copy code
ts
export default function handler(req: NextApiRequest, res: NextApiResponse) {
  supabase.auth.api.setAuthCookie(req, res)
}
. Does anyone know how to get user once logged into the protected page? 🤔
s
Please use the
@supabase/supabase-auth-helpers
to get this feature out of the box. https://github.com/supabase-community/supabase-auth-helpers
p
Thanks ❤️