next-auth: Types of property 'createUser' are incompatible

Environment

System: OS: Windows 11 10.0.22000 CPU: (32) x64 AMD Ryzen 9 3950X 16-Core Processor Memory: 88.88 GB / 127.94 GB Binaries: Node: 20.6.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD pnpm: 8.13.1 - C:\Program Files\nodejs\pnpm.CMD Browsers: Edge: Spartan (44.22000.120.0), Chromium (120.0.2210.91) Internet Explorer: 11.0.22000.120 npmPackages: @auth/core: ^0.19.0 => 0.19.0 @auth/sequelize-adapter: ^1.0.12 => 1.0.12 next: ^14.0.4 => 14.0.4 next-auth: ^4.24.5 => 4.24.5 react: ^18.2.0 => 18.2.0

Reproduction URL

https://github.com/Master-Guy/next-auth-issue

Describe the issue

After upgrading to the latest version of @auth-sequelize TypeScript is complaining about the Adapter not being correct anymore. The code has not been changed at all. Even though TypeScript shows an error, node dev runs without issues and I don’t (yet) experience any problems on my project.

[{
	"resource": "/f:/Programming/Github/Navis/src/pages/api/auth/[...nextauth].tsx",
	"owner": "typescript",
	"code": "2322",
	"severity": 8,
	"message": "Type 'import(\"f:/Programming/Github/Navis/node_modules/@auth/core/adapters\").Adapter' is not assignable to type 'import(\"f:/Programming/Github/Navis/node_modules/next-auth/adapters\").Adapter'.\n  Types of property 'createUser' are incompatible.\n    Type '((user: AdapterUser) => Awaitable<AdapterUser>) | undefined' is not assignable to type '((user: Omit<AdapterUser, \"id\">) => Awaitable<AdapterUser>) | undefined'.\n      Type '(user: AdapterUser) => Awaitable<AdapterUser>' is not assignable to type '(user: Omit<AdapterUser, \"id\">) => Awaitable<AdapterUser>'.\n        Types of parameters 'user' and 'user' are incompatible.\n          Property 'id' is missing in type 'Omit<AdapterUser, \"id\">' but required in type 'AdapterUser'.",
	"source": "ts",
	"startLineNumber": 93,
	"startColumn": 2,
	"endLineNumber": 93,
	"endColumn": 9,
	"relatedInformation": [
		{
			"startLineNumber": 174,
			"startColumn": 5,
			"endLineNumber": 174,
			"endColumn": 7,
			"message": "'id' is declared here.",
			"resource": "/f:/Programming/Github/Navis/node_modules/@auth/core/adapters.d.ts"
		},
		{
			"startLineNumber": 106,
			"startColumn": 5,
			"endLineNumber": 106,
			"endColumn": 12,
			"message": "The expected type comes from property 'adapter' which is declared here on type 'AuthOptions'",
			"resource": "/f:/Programming/Github/Navis/node_modules/next-auth/core/types.d.ts"
		}
	]
}]

How to reproduce

See repo

Expected behavior

No TypeScript errors

About this issue

  • Original URL
  • State: open
  • Created 6 months ago
  • Reactions: 15
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

In the meanwhile you can infer the Adapter type from next-auth/adapters

import type { Adapter } from 'next-auth/adapters';

[...]
adapter: PrismaAdapter(prisma) as Adapter

This results in very bad user experience for a new developer, since they literally copy and paste the code from the documentation and it results in an obscure type error. This should get fixed ASAP.

Same with the drizzle adapters. Had to cast the DrizzleAdapter from “@auth/drizzle-adapter” as an Adapter from “next-auth/adapters”;

Hi everyone, just wanted to let you know, this is known.

It’s related to #9380, after which the types in @auth/core/adapters are slightly different than what next-auth v4 expects. Since @auth/*-adapters are designed in a way to keep working with next-auth v4, you are seeing this error now (type only!). However the actual implementation of the adapters have not changed yet (#9381), it is technically safe to ignore the type error by either of these:

  1. // @ts-expect-error for now
  2. downgrade your adapter to a lower version, until this error goes away

[!NOTE] Nothing has changed in the adapter implementation and stayed the same for years, and #9380 is actually an attempt to make it even smoother to create new adapters, by delegating the repetitive task of creating the user id to the core library instead (see #9381)

The real solution to this issue would be to backport #9380 and #9793 to v4 https://github.com/nextauthjs/next-auth/tree/v4/packages/next-auth, so the old Adapter type

https://github.com/nextauthjs/next-auth/blob/9296222ffdf56d0f04d08593161d3fe26b0f308b/packages/next-auth/src/adapters.ts#L63

can match up with the new one:

https://github.com/nextauthjs/next-auth/blob/f5fb578f0b324af9cb392e7aa8e8bfbf0d90e0ce/packages/core/src/adapters.ts#L271

Until that is done, #9381 is pending and won’t make changes to any of the adapters to keep things run smoothly.

If anyone is up for making a PR to v4, I’m happy to review!

Same thing happening with @auth/mongodb-adapter@2.0.10 and next-auth@4.24.5.

This results in very bad user experience for a new developer, since they literally copy and paste the code from the documentation and it results in an obscure type error. This should get fixed ASAP.

agreed, type incompatibilities between internal libraries is not a great look while evaluating an authentication provider

Same with Drizzle Adapter Seems like all adapter types are somehow broken. Is there a reason to omit the ids that I am not able to understand?

In the meanwhile you can infer the Adapter type from next-auth/adapters

import type { Adapter } from 'next-auth/adapters';

[...]
adapter: PrismaAdapter(prisma) as Adapter

Thanks! this fixed the issue, I hope something is done about it soon.

Same thing happening with PrismaAdapter.

Screenshot from 2024-01-08 01-02-35

import type { Adapter } from "next-auth/adapters"; Fixes the issue for now.

In the meanwhile you can infer the Adapter type from next-auth/adapters

import type { Adapter } from 'next-auth/adapters';

[...]
adapter: PrismaAdapter(prisma) as Adapter