Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
Authentication with axios throwing internal server error in Next JS

Getting 500 internal server error for my next authentication.

I implemented everything according to the docs from Next Auth.

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import axios from "axios";
import { API_URL } from "./../../../helpers/api/mutations";

const options = {
  providers: [
    CredentialsProvider({
      name: "Credentials",

API works fine in a separate react component but fails only on Next Auth.

      async authorize(credentials) {
        const user = axios({
          url: API_URL,
          method: "post",
          data: {
            query: `mutation($mobileNumber:String,$mobileCountryCode:String,$otp:Int){
              verifyPhoneOTP(
            mobileNumber: $mobileNumber,
             mobileCountryCode: $mobileCountryCode,
                otp:$otp
              )
              {accessToken
              expiresAt}
            }`,
            variables: {
              mobileNumber: credentials.mobile,
              mobileCountryCode: credentials.email,
              otp: credentials.otpFormatt,
            },
          },
          validateStatus: (status) => {
            if (status == 500) {
              console.log(status, "status axios log");
              console.log(credentials, "credentials log");
              return true;
            }
          },
          headers: {
            "User-Agent":
              "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36",
            Accept: "application/json; charset=UTF-8",
          },
        })
          .catch((error) => {
            console.log(error.response.data, "axios fail calls");
          })
          .then((result) => {

Currently I can see this console log "axios calls" successfully displays itself on the terminal but the tokens and sessions aren't returned.

            console.log(result.data, "axios calls");
            console.log(credentials, "creds");
                return result.data.data 
          });
        if (user) {
          return user;
        } else {
          return null;
        }
      },
    }),
  ],
};


const callbacks = {
  async jwt(token, user) {
    if (user) {
      token.accessToken = user.token;
    }

    return token;
  },
  
  secret:process.env.SECRET,

  async session(session, token) {
    session.accessToken = token.accessToken;
    return session;
  },
};

export default (req, res) => NextAuth(req, res, options);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Error 500 means server error. Check you api server whether it is running or stopped. Error 500 here has nothing to do with nextjs, it is all about the back-end server.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda