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

802
Vistas
Stuck with Next Auth authorize part. Error: Action api with HTTP GET is not supported by NextAuth.js

I'm getting a strange error for the past few days. Unable to authenticate my Next.js app with credentials.

As far as I know everything is correct according to the doc.

I'm also unable to see a network request in my chrome dev tools.

import NextAuth from "next-auth";
import CredentialProvider from "next-auth/providers/credentials";
import { signOut,useSession,signIn } from 'next-auth/react';
import { axios } from 'axios';
import { API_URL } from "../../../helpers/api/mutations";

export default NextAuth({
  providers: [
    CredentialProvider({
      name: "credentials",
      credentials: {
        username: {
          label: "Email",
          type: "text",
          placeholder: "mani@test.com"
        },
        password: {
          label: "Password",
          type: "password"
        }},
        // My authorize function where I called my graphql mutation for token and session.
        async authorize(credentials,req) {
            const {data} = await axios({
              url: API_URL,
              method: 'post',
              data: {
               query: `mutation {
                login(
                   mobileNumber: "4738291046",
                  mobileCountryCode: "00",
                  password: "admin123"
                ) {
                  expiresAt
                  accessToken
                }
              }`
              }
             })
              .then(res => {
               console.log(res.data);
              })
              .catch(err => {
               console.log(err.message);
              });

              if (data) {
                console.log(data,'dataaa');
                return data
              }
              else {
                return null
              }
        }
    }),
  ],
  callbacks: {
    jwt: ({ token, user }) => {
      // first time jwt callback is run, user object is available
      if (user) {
        token.id = user.id;
      }

      return token;
    },
    session: ({ session, token }) => {
      if (token) {
        session.id = token.id;
      }

      return session;
    },
  },
   secret: "test",
   jwt: {
       secret:"test",
       encryption: true,
   },
   pages: {
    signIn: "api/auth/sigin",
  },
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I ran into this because I forgot the leading / in my custom signIn page value:

pages: {
  signIn: "/api/auth/sigin",
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem may be related on how you have handled async/await in the authorize function.

Try to change it like this:

async authorize(credentials,req) {
    try {
        const { data } = await axios({
            url: API_URL,
            method: 'post',
            data: {
                query: `mutation {
                    login(
                    mobileNumber: "4738291046",
                    mobileCountryCode: "00",
                    password: "admin123"
                    ) {
                    expiresAt
                    accessToken
                    }
                }`
            }
        })

        if (data) {
            console.log(data,'dataaa');
            return data
        }
        else {
            return null
        }
    } catch (err) {
        return null
    }
}
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