ค้นหาเว็บไซต์

javascript - ข้อผิดพลาด NextAuth แสดงว่า expression ไม่สามารถเรียกใช้งานได้


ดังนั้นฉันกำลังเรียนรู้การตรวจสอบตัวตนใน Next.js โดยใช้ next-auth ฉันได้ทำตามเอกสารและนี่คือโค้ด app/api/auth/[...nextauth]/route.ts ของฉัน

import NextAuth, { type NextAuthOptions } from "next-auth";
import GithubProvider from "next-auth/providers/github";
import CredentialsProvider from "next-auth/providers/credentials";

export const authOptions: NextAuthOptions = {
  providers: [
    GithubProvider({
      clientId: process.env.GITHUB_ID as string,
      clientSecret: process.env.GITHUB_SECRET as string,
    }),

    CredentialsProvider({
      name: "Credentials",
      credentials: {
        username: {
          label: "Username",
          type: "text",
          placeholder: "John Smith",
        },
        password: {
          label: "Password",
          type: "password",
          placeholder: "*******",
        },
      },
      async authorize(credentials) {
        // here data should come from the database
        const user = { id: "1", name: "John", password: "pass" };
        if (
          credentials?.username === user.name &&
          credentials.password === user.password
        ) {
          return user;
        } else {
          return null;
        }
      },
    }),
  ],
};
const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

ฉันกำลังได้รับข้อผิดพลาดในไฟล์นี้ที่ระบุว่า

This expression is not callable.
  Type 'typeof import("e:/Javascript/learnauth2/node_modules/next-auth/next")' has no call signatures.ts(2349)

เวอร์ชันของ next-auth ที่ฉันมีคือ 4.22.2 และเวอร์ชันของ next คือ 13.4.10

ยินดีรับความช่วยเหลือเกี่ยวกับเรื่องนี้

คำตอบ #1

ดังนั้นฉันคิดว่าฉันพบวิธีแก้ปัญหานี้แล้ว ฉันลองใช้ npm update และบูม! ไม่มีข้อผิดพลาดใด ๆ ไม่รู้ว่าปัญหาหลักคืออะไร

บทความที่เกี่ยวข้อง