Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Next Auth authentication in production

I finished developing my application with Next.js. I used Next Auth to handle user authentication. I use the Credential Provider for authentication with email and password.

In development everything works fine when I log in the session is well created and a JWT token is well generated.

On the other hand when putting in production it does not work, I have the following error:

[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error invalid json response body at https://my-site.fr/api/auth/csrf reason: Unexpected token < in JSON at position 0 {

I really don't understand why the error only appears in production.

Here is the code of my Credential Provider

CredentialProvider({
      async authorize(credentials, req) {
        // console.log(credentials);
        const url = `${process.env.NEXT_PUBLIC_API}/auth/login`;

        const res = await fetch(url, {
          method: "POST",
          body: JSON.stringify(credentials),
          headers: {
            "Content-Type": "application/json",
            Accept: "application/json, text/plain, */*'",
            "User-Agent": "*",
          },
        });

        // console.log(res);
        const user = await res.json(res);

        if (res.ok && user) {
          return user;
        }

        return null;
      },
    }),

Thanks for your help.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!