Closed OrJDev closed 1 year ago
Had this same issue in a SvelteKit project. Type assertion worked for me and didn't get errors on runtime, should be a good temporary solution.
import SvelteKitAuth from '@auth/sveltekit'; // Using SvelteKit as an example
import type { Adapter } from '@auth/core/adapters';
export const handle = SvelteKitAuth({
adapter: PrismaAdapter(prismaClient) as Adapter<boolean>,
providers: [
// ...
]
});
Had this same issue in a SvelteKit project. Type assertion worked for me and didn't get errors on runtime, should be a good temporary solution.
import SvelteKitAuth from '@auth/sveltekit'; // Using SvelteKit as an example import type { Adapter } from '@auth/core/adapters'; export const handle = SvelteKitAuth({ adapter: PrismaAdapter(prismaClient) as Adapter<boolean>, providers: [ // ... ] });
this works for now
I got the feedback that Type 'Adapter' is not generic.
export const handle = SvelteKitAuth({
adapter: PrismaAdapter(prisma) as Adapter,
providers: [
...
]
});
@kalm42 me too
+1
try this
import type { Adapter } from 'next-auth/adapters';
...
adapter: TypeORMAdapter(connection) as Adapter,
P.S. No matter which adapter you have, it should help with every adapters
Hi @YuraD can you please explain with more context.
I am not able to understand what is connection
here? Also what do you mean by TypeORMAdapter
? where can I import this function?
I am errors in the Prisma adapter index.ts
One of the errors:
Type '(email: string) => Prisma__UserClient<User | null, null>' is not assignable to type '(email: string) => Awaitable<AdapterUser | null>'.
Type 'Prisma__UserClient<User | null, null>' is not assignable to type 'Awaitable<AdapterUser | null>'.
@ShriPunta this is more about the Adapter
and typescript types I think. Adding the Adapter
worked for prisma as well
import type { Adapter } from 'next-auth/adapters';
...
export const authConfig: NextAuthOptions = {
adapter: PrismaAdapter(db) as Adapter,
...
TypeORMAdapter is a sibling or alternative to PrismaAdapter, both are one of the many adapters for next-auth
got no issues in this case
Which Schema should I use with "@next-auth/prisma-adapter"? The one shown in the v3 version or the one shown for "@auth/prisma-adapter"?
next-auth v3: https://next-auth.js.org/v3/adapters/prisma auth: https://authjs.dev/reference/adapter/prisma
Looks like the module @next-auth/adapters is no longer existing, so the only solution is using @next-auth/prisma-adapter. I would suggest fixing the docs, or fixing the package
use @auth/prisma-adapter
to solve this issue
Why was this issue closed? I just set up my Next JS project with
"@auth/prisma-adapter": "^1.0.1"
"next-auth": "^4.22.5"
and I'm having the exact same problems as everyone mentioned.
So I installed "@next-auth/prisma-adapter": "^1.0.7"
which works for me.
Please fix either your documentation about the prisma adapter or fix the type error for the newest versions of next-auth
and @auth/prisma-adapter
.
@Puetz as @next-auth
is becoming @auth
that's probably not the right way.
@OrJDev please re-open as the problem still persists, even with latest @auth/prisma-adapter
.
Why was this issue closed? I just set up my Next JS project with
"@auth/prisma-adapter": "^1.0.1" "next-auth": "^4.22.5"
and I'm having the exact same problems as everyone mentioned. So I installed
"@next-auth/prisma-adapter": "^1.0.7"
which works for me.Please fix either your documentation about the prisma adapter or fix the type error for the newest versions of
next-auth
and@auth/prisma-adapter
.
This fixed my problem also. I think they should update a documentation a bit. Maybe we can help them? Open a pr? Because right now i feel a bit lost.
I can confirm that I'm still having type errors with the latest versions:
Using this Schema.
"@auth/prisma-adapter": "^1.0.1",
"next-auth": "^4.23.1",
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(db),
// ^~~~~ TypeError
providers: [getEmailProvider()],
//...
}
Error:
ype 'import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/adapters").Adapter'.
Types of property 'linkAccount' are incompatible.
Type '((account: import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapters").AdapterAccount) => Promise<void> | import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/types").Awaitable<import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapt...' is not assignable to type '((account: import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/adapters").AdapterAccount) => Promise<...> | import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/types").Awaita...'.
Type '(account: import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapters").AdapterAccount) => Promise<void> | import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/types").Awaitable<import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapte...' is not assignable to type '(account: import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/adapters").AdapterAccount) => Promise<...> | import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/core/types").Awaitab...'.
Types of parameters 'account' and 'account' are incompatible.
Type 'import("/workspace/node_modules/.pnpm/next-auth@4.23.1_next@13.4.12_react-dom@18.2.0_react@18.2.0/node_modules/next-auth/adapters").AdapterAccount' is not assignable to type 'import("/workspace/node_modules/.pnpm/@auth+core@0.9.0/node_modules/@auth/core/adapters").AdapterAccount'.
Types of property 'type' are incompatible.
Type 'ProviderType' is not assignable to type '"email" | "oidc" | "oauth"'.
Type '"credentials"' is not assignable to type '"email" | "oidc" | "oauth"'.ts(2322)
types.d.ts(106, 5): The expected type comes from property 'adapter' which is declared here on type 'AuthOptions'
No errors when using latest @next-auth/prisma-adapter
Not sure if it can help someone, but I solved it by using:
import { Adapter } from 'next-auth/adapters';
import { PrismaAdapter } from '@auth/prisma-adapter';
const nextAuthOptions = {
...,
adapter: <Adapter>PrismaAdapter(prismaClient),
...,
With versions:
...
"next-auth": "^4.24.5",
"@auth/prisma-adapter": "^1.3.3",
...
casting the adapter to Adapter
is still necessary to avoid type errors with
"@auth/prisma-adapter": "^2.4.2",
"next-auth": "5.0.0-beta.4",
"@auth/prisma-adapter": "^2.4.2",
"next-auth": "5.0.0-beta.4",
If I adopt this approach, there will be no problem.
getting this error. The only workaround I can find right now is adding type: module
EDIT: I am using turbo repo so it was a bit hard but for me, the culprit was tsconfig.json
added this:
"extends": "@repo/typescript-config/react-library.json",
"compilerOptions": {
"outDir": "dist",
"module": "ESNext", // Added to support ES Modules
"moduleResolution": "Node", // Added to resolve imports correctly
"esModuleInterop": true // Added to enable ES Module interop
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
Adapter type
@next-auth/prisma-adapter
Environment
System: OS: Windows 10 10.0.19045 Memory: 991.97 MB / 5.95 GB Binaries: Node: 16.13.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD npm: 8.16.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.1266.0), Chromium (108.0.1462.54)
Internet Explorer: 11.0.19041.1566
npmPackages: @next-auth/prisma-adapter: ^1.0.5 => 1.0.5
Reproduction URL
https://github.com/OrJDev/nextauth-error-repro
Describe the issue
How to reproduce
run
select prisma and nextauth go to src/routes/api/auth/[...solidauth].ts the error will be there
Expected behavior
shouldn't throw any type errors with a normal prisma client (no extension)