0

I have an e-commerce that I deploy into vercel, I used next-auth for authentication, when i try to login it's complains and launch an error

enter image description here

[nextauth].ts

export default NextAuth({
  providers: [
    Credentials({
      name: "Custom Login",
      credentials: {
        email: {
          label: "Correo:",
          type: "email",
          placeholder: "correo@google.com",
        },
        password: {
          label: "Contraseña:",
          type: "password",
          placeholder: "Contraseña",
        },
      },
      async authorize(credentials) {
        console.log({ credentials });

        return await dbUsers.checkUserEmailPassword(
          credentials!.email,
          credentials!.password
        );
      },
    }),

login.tsx

const onLoginUser = async ({ email, password }: FormData) => {
    setShowError(false);

    await signIn("credentials", { email, password });

    
  };

this is my response:

[![2022-06-23T08:45:36.199Z 33d4ff25-ada2-4054-9050-68eec5626886    ERROR   \[next-auth\]\[error\]\[CLIENT_FETCH_ERROR\] 
https://next-auth.js.org/errors#client_fetch_error invalid json response body at https://madrugon-8dxawm6jh-madrugon-admin.vercel.app/api/auth/session reason: Unexpected token < in JSON at position 0 {
  error: {
    message: 'invalid json response body at https://madrugon-8dxawm6jh-madrugon-admin.vercel.app/api/auth/session reason: Unexpected token < in JSON at position 0',
    stack: 'FetchError: invalid json response body at https://madrugon-8dxawm6jh-madrugon-admin.vercel.app/api/auth/session reason: Unexpected token < in JSON at position 0\n' +
      '    at /var/task/node_modules/next/dist/compiled/node-fetch/index.js:1:49606\n' +
      '    at processTicksAndRejections (node:internal/process/task_queues:96:5)',
    name: 'FetchError'
  },
  path: 'session',][1]][1]

in heroku and locally works perfect but not in custom domain in vercel ¿can you help me?

Link of custom domain

Link on heroku

My repo

I have reviewed and it seems that one of my problems is that the providers are not read

  • Have you correctly configured your environment variables in Vercel? – juliomalves Jun 25 '22 at 17:38
  • I've been thinking about it and I've corrected it twice and it doesn't work. Could you look at the env.template and check if I'm ok – FELIX EDUARDO MIRANDA TERAN Jun 26 '22 at 03:18
  • Ran into this issue as well: https://stackoverflow.com/questions/72469610/nextauth-api-auth-always-return-404-on-vercel-deployment-but-work-locally The issue may be related to deploying it on Vercel, maybe you could try deploying it elsewhere like Netlify to verify that the issue only happens on Vercel? – learning_developer_9 Jul 04 '22 at 14:24
  • I deployed in Heroku and it works :( – FELIX EDUARDO MIRANDA TERAN Jul 06 '22 at 00:16
  • So you had trouble with Vercel and ended up in Heroku? were you able to deploy again to Vercel or never tried again? I am facing the same problem. – TOPAiiN Oct 19 '22 at 16:05
  • How about trying it on Render (where I work)? You can use a custom domain. Here's a quickstart for Next.js that I hope will help: https://render.com/docs/deploy-nextjs-app – Dnilasor Oct 19 '22 at 23:18

0 Answers0