0

I'm receiving the following error with certificates when trying to fetch the user from Supabase inside getServerSideProps with Next.js:

AuthRetryableFetchError: request to https://[redacted].supabase.co/auth/v1/user failed, reason: self signed certificate in certificate chain
    at [redacted]/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:30:16

This is a simplified version of my code for reference:

export const getServerSideProps = async ({ req, res }) => {
  const supabase = createServerSupabaseClient({ req, res });
  const { data: { user }, error } = await supabase.auth.getUser();

  if (error) console.error(error);

  return {
    props: {
      user,
    }
  }
};

I've already setup yarn and npm to both use the right certificate using yarn config set cafile /path/to/certificate/file and npm config set cafile /path/to/certificate/file respectively, but for some reason when Next.js tries to get this from the server side (Node.js) it fails, and I'm not sure what service I need to setup to tell it where the certificate is set?

There are a lot of similar questions out there, but I couldn't find any specifically about Next.js or hitting this issue in Node.js.

Any help appreciated.

fredrivett
  • 5,419
  • 3
  • 35
  • 48

1 Answers1

0

So it seems to be possible to get round this issue with setting NODE_TLS_REJECT_UNAUTHORIZED=0 in env.local, but if anyone knows how to fix the issue rather than avoid it I'd be interested still.

src: https://stackoverflow.com/a/45088585/827129

fredrivett
  • 5,419
  • 3
  • 35
  • 48
  • Have you ever been able to resolve this? I'm getting the same error on a local supabase environment, since I switched from Docker Desktop to Colima. But setting `NODE_TLS_REJECT_UNAUTHORIZED=0` does not help. – riccardolardi Apr 06 '23 at 08:33
  • @riccardolardi sadly not, I’ve not revisited this issue since my work around got me past it – fredrivett Apr 07 '23 at 10:41