我正在遵循此文档: https: //authjs.dev/reference/adapter/mongodb以使用 next-auth。这是相关代码:
import NextAuth from "next-auth"
import { MongoDBAdapter } from "@auth/mongodb-adapter"
import clientPromise from "../../../lib/mongodb"
...
export default NextAuth({
providers,
adapter: MongoDBAdapter(clientPromise),
})
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,这对我来说毫无意义:
Type 'Adapter' is not assignable to type 'Adapter | undefined'.
Type 'Adapter' is not assignable to type 'DefaultAdapter & { createVerificationToken: (verificationToken: VerificationToken) => Awaitable<VerificationToken | null | undefined>; useVerificationToken: (params: { ...; }) => Awaitable<...>; }'.
Type 'Adapter' is not assignable to type 'DefaultAdapter'.
Types of property 'createUser' are incompatible.
Type '((user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>) | undefined' is not assignable to type '(user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>'.
Type 'undefined' is not assignable to type '(user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>'.ts(2322)
types.d.ts(106, 5): The expected type comes from property 'adapter' which is declared here on type 'AuthOptions'
(property) AuthOptions.adapter?: Adapter | undefined
You can use the adapter option to pass in your database adapter.
Required: No
Run Code Online (Sandbox Code Playgroud)
Rga*_*r43 20
我今天遇到了同样的问题。我从 @auth/mongodb-adapter 导入 MongoDBAdapter,但实际上需要从 next-auth 适配器导入。
我跑:
npm install @next-auth/mongodb-adapter
Run Code Online (Sandbox Code Playgroud)
然后将我的导入更改为:
import { MongoDBAdapter } from "@next-auth/mongodb-adapter";
Run Code Online (Sandbox Code Playgroud)
我不知道实际问题是什么,只是安装正确的适配器并更改导入为我修复了它。
希望这可以帮助!
小智 17
我遇到了相同类型的错误@auth/firebase-adapter。
ype error: Type 'Adapter' is not assignable to type 'Adapter | undefined'.
Type 'Adapter' is not assignable to type 'DefaultAdapter & { createVerificationToken: (verificationToken: VerificationToken) => Awaitable<VerificationToken | null | undefined>; useVerificationToken: (params: { ...; }) => Awaitable<...>; }'.
Type 'Adapter' is not assignable to type 'DefaultAdapter'.
Types of property 'createUser' are incompatible.
Type '((user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>) | undefined' is not assignable to type '(user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>'.
Type 'undefined' is not assignable to type '(user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>'
Run Code Online (Sandbox Code Playgroud)
首先,Adapter从导入类型next-auth/adapters。
import type { Adapter } from "next-auth/adapters";
Run Code Online (Sandbox Code Playgroud)
并更改 NextAuthOptions。
import type { Adapter } from "next-auth/adapters";
export const authOptions: NextAuthOptions = {,
adapter: FirestoreAdapter(firestore) as Adapter,
...
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5454 次 |
| 最近记录: |