0

What is the correct way to declare the authorize function in [...nextauth].ts?? I'm tryin it like this:

 export default NextAuth({
        session: {
                strategy: "jwt"
        },
        providers:[CredentialsProvider({
                async authorize(credentials:Record<string,string>){
                        dbConnect()
                        const {email,password} = credentials as {
                                email: string,
                                password: string,
                              };;      
                        const user = await User.findOne({ email: email})
                        if(!user){
                                throw new Error("Invalid email or password")
                        }
                        const isPasswordMatched = await bcrypt.compare(password, user.password )
                        if(!isPasswordMatched){
                                throw new Error("Invalid email or password")
                        }
                        return user;

                }
        })]

})

but authorize is highlighting error which is:

Type '(credentials: Record<string, string>) => Promise<any>' is not assignable to type '(credentials: Record<string, string> | undefined, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Awaitable<User | null>'.
  Types of parameters 'credentials' and 'credentials' are incompatible.
    Type 'Record<string, string> | undefined' is not assignable to type 'Record<string, string>'.
      Type 'undefined' is not assignable to type 'Record<string, string>'.ts(2322)
credentials.d.ts(13, 5): The expected type comes from property 'authorize' which is declared here on type 'UserCredentialsConfig<Record<string, CredentialInput>>'

what does that mean??

naeemgg
  • 177
  • 1
  • 8

1 Answers1

0

tsconfig.json ("strict": false )

no more restrictions to your code. The below link helps you to understand strict mode

https://dev.to/jsdev/strict-mode-typescript-j8p

Naveen Nizam
  • 193
  • 8