next-auth: TypeScript error for the Credentials provider
Description 🐜
The changes to Providers in […nextauth].ts in V4 appered a TypeScript error for the Credentials provider.
Type 'CredentialsConfig<{ username: { label: string; type: string; }; password: { label: string; type: string; }; }>' is not assignable to type 'Provider'.
Type 'CredentialsConfig<{ username: { label: string; type: string; }; password: { label: string; type: string; }; }>' is not assignable to type 'CredentialsConfig<{}>'.
Types of property 'authorize' are incompatible.
Type '(credentials: Record<"username" | "password", string>, req: NextApiRequest) => Awaitable<Omit<User, "id"> | { id?: string | undefined; } | null>' is not assignable to type '(credentials: Record<never, string>, req: NextApiRequest) => Awaitable<Omit<User, "id"> | { id?: string | undefined; } | null>'.
Types of parameters 'credentials' and 'credentials' are incompatible.
Type 'Record<never, string>' is missing the following properties from type 'Record<"username" | "password", string>': username, password
Is this a bug in your own project?
No
How to reproduce ☕️
import bcrypt from 'bcryptjs';
import prisma from 'lib/prisma';
import NextAuth from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
export default NextAuth({
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text' },
password: { label: 'Password', type: 'password' }
},
async authorize(credentials: any, req) {
const user = await prisma.user.findUnique({
where: {
username: credentials.username
}
});
if (!user) {
return null;
}
const valid = await bcrypt.compare(credentials.password, user.password);
if (!valid) {
console.log(`Credentials not valid`);
return null;
}
if (user) {
return { ...user, email: user.username };
}
return null;
}
})
]
});
Screenshots / Logs 📽
No response
Environment 🖥
System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel® Core™ i5-1035G1 CPU @ 1.00GHz Memory: 3.44 GB / 11.81 GB Binaries: Node: 14.15.4 - D:\Node\node.EXE npm: 6.14.10 - D:\Node\npm.CMD Browsers: Edge: Spartan (44.19041.1023.0), Chromium (93.0.961.38) Internet Explorer: 11.0.19041.906 npmPackages: next: ^10.2.3 => 10.2.3 next-auth: ^4.0.0-beta.2 => 4.0.0-beta.2 react: ^17.0.2 => 17.0.2
Contributing 🙌🏽
No, I am afraid I cannot help regarding this
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 34 (7 by maintainers)
Nextjs with its 4,555,332,233 issue. Keep it up Vercel!
Bumping this, still an issue as of May 2023. My workaround was to simply type the return as
any:Instead of changing the strict setting in the tsconfig I highly recommend just using tsignore
Maybe a difference in the
tsconfig.jsoncausing this?I have to go now, but please keep digging 🙏
Update: it’s the
strictflag.next-authis being developed withstrict: false.If I turn it to
true, other stuff might break too… (counted 62 errors when I rantsc) This might be a bigger issue then. For now, you could setstrict: false, and the error will go away. I’ll have to investigate this further and decide what we should do. 🤔I will close this in favour of #2709.
The current fix for this issue is to turn off strict mode in
tsconfig.json.The issue is when the
tsconfig.jsonhas strict mode turned on:"strict":true,can someone reopen this issue please? there are still a lot of people wanting to pass custom user data from the
authorizemethod. also i got the same barrier when needing to pass the custom data to the session. why are we forced into this basic type again?export interface DefaultUser { id: string name?: string | null email?: string | null image?: string | null }why has this been closed if the issue still exists when
"strict": true?Sweet man, thank you for all your time working with me on this. For now I’ll set strict to false, but would be awesome to support strict mode too 😃 But totally get if that would be a ballache.
Me too man, me too 😂
Now that just doesn’t make sense to my brain… 👀
Works like a charm ! 👍
fixed it for me
does anyone have a fix for this? im also getting this error.
Here’s a reproducible issue: https://codesandbox.io/s/charming-feynman-0p5gf?file=/src/pages/api/auth/[...nextauth].ts
I literally pasted the code from above. 😅
You ask me for a reproduction of a working example? 😄 I’ll create one, fine.