Awaitable <User | null> not assignable to <Promise <User | null>> #13098
Unanswered
RobinSuthar
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am Getting a error at authorize function
This is what the error says
Type '(credentials: Record<"username" | "password", string> | undefined, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Promise<...>' is not assignable to type '(credentials: Record<"username" | "password", string> | undefined, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Awaitable<...>'.
Type 'Promise<{ id: number; Username: string; Password: string; } | undefined>' is not assignable to type 'Awaitable<User | null>'.
Type 'Promise<{ id: number; Username: string; Password: string; } | undefined>' is not assignable to type 'PromiseLike<User | null>'.
Types of property 'then' are incompatible.
Type '<TResult1 = { id: number; Username: string; Password: string; } | undefined, TResult2 = never>(onfulfilled?: ((value: { id: number; Username: string; Password: string; } | undefined) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... ...' is not assignable to type '<TResult1 = User | null, TResult2 = never>(onfulfilled?: ((value: User | null) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => PromiseLike<...>'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type '{ id: number; Username: string; Password: string; } | undefined' is not assignable to type 'User | null'.
Type 'undefined' is not assignable to type 'User | null'.ts(2322)
credentials.d.ts(13, 5): The expected type comes from property 'authorize' which is declared here on type 'UserCredentialsConfig<{ username: { label: string; type: string; placeholder: string; }; password: { label: string; type: string; }; }>'
This is the Code :
import database from "@/database/db";
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
const handler = NextAuth({
providers: [
CredentialsProvider({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: "Credentials",
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
// You can pass any HTML attribute to the tag through the object.
credentials: {
username: {
label: "Username",
type: "text",
placeholder: "Enter your username",
},
password: {
label: "Password",
type: "password",
},
},
async authorize(credentials, req) {
console.log(req)
const result = await database.user.findFirst({
where: {
Username: credentials?.username,
Password: credentials?.password,
},
});
// You need to provide your own logic here that takes the credentials
// submitted and returns either a object representing a user or value
// that is false/null if the credentials are invalid.
// e.g. return { id: 1, name: 'J Smith', email: '[email protected]' }
// You can also use the
req
object to obtain additional parameters// (i.e., the request IP address)
if (result) {
return result;
}
},
}),
],
secret: process.env.NEXTAUTH_SECRET,
});
export { handler as GET, handler as POST };
Beta Was this translation helpful? Give feedback.
All reactions