卡在下一个身份验证授权部分。错误:NextAuth.js 不支持使用 HTTP GET 的操作 api

Man*_*dan 3 javascript node.js reactjs next.js next-auth

过去几天我收到一个奇怪的错误。无法使用凭据验证我的 Next.js 应用程序。

据我所知,根据文档,一切都是正确的。

我也无法在 Chrome 开发工具中看到网络请求。

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",
  },
});
Run Code Online (Sandbox Code Playgroud)

nin*_*sau 15

这是你的文件结构。确保它[...nextauth].ts位于正确的路径中/pages/api/auth/[...nextauth].ts

  • 注意:使用 Next 13 应用程序目录,路径应为 `app\api\auth\[...nextauth]\route.js` (3认同)