NextAuth在嵌入Typescript时显示错误

yvgpqqbh  于 2023-06-29  发布在  TypeScript
关注(0)|答案(1)|浏览(97)

如果我尝试使用Typescript将NextAuth集成到我的应用程序中,我会得到2个错误。一次在NextAuth和NextAuthOptions。

import NextAuth from "next-auth"
import { NextAuthOptions } from "next-auth"
import GoogleProvider from "next-auth/providers/google";

export const authOptions: NextAuthOptions = ({
 providers: [
    GoogleProvider({
      clientId: `${process.env.GOOGLE_CLIENT_ID}`,
      clientSecret: `${process.env.GOOGLE_CLIENT_SECRET}`, 
    })
  ]
})

const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }

模块“next-auth”没有导出的成员“NextAuthOptions '. ts”(2305)
此表达式不可调用。类型“typeof import(“next-auth”)”没有调用签名。

66bbxpm5

66bbxpm51#

import NextAuth, { AuthOptions } from "next-auth";
    import GoogleProvider from "next-auth/providers/google";

    export const authOptions: AuthOptions = {
     providers: [
      GoogleProvider({
      clientId: String(process.env.GOOGLE_CLIENT_ID),
      clientSecret: String(process.env.GOOGLE_CLIENT_SECRET),
      }),
     ],
    };

  export default NextAuth(authOptions);

相关问题