Encountering a type error in the authorize function while using NextAuth with CredentialsProvider
export const authOptions : NextAuthOptions ={
session : { strategy: "jwt" },
providers : [ CredentialsProvider({
async authorize( credentials ) {
const { email , password } = credentials;
try{
await connectDB()
} catch ( err ){
console.log( err );
throw new Error( ERROR.SERVER_ERROR );
}
if ( !email || !password ) throw new Error( ERROR.INVALID_DATA );
const user = await User.findOne({ email })
if( !user ) throw new Error( ERROR.CREATE_ACCOUNT )
const isValid = await verifyPassword( password , user.password )
if ( !isValid ) throw new Error( ERROR.WRONG_PASSWORD )
return { email }
}
})]
}
const handler = NextAuth (authOptions);
export { handler as GET, handler as POST };
Error message :
Type '(credentials: Record<string, string>) => Promise<{ email: string; }>' is not assignable to type '(credentials: Record<string, string>, req: Pick<RequestInternal, "body" | "query" | "headers" | "method">) => Awaitable<User>'.
Type 'Promise<{ email: string; }>' is not assignable to type 'Awaitable<User>'.
Type 'Promise<{ email: string; }>' is not assignable to type 'PromiseLike<User>'.
Types of property 'then' are incompatible.
Type '<TResult1 = { email: string; }, TResult2 = never>(onfulfilled?: (value: { email: string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<...>) => Promise<...>' is not assignable to type '<TResult1 = User, TResult2 = never>(onfulfilled?: (value: User) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => PromiseLike<...>'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Property 'id' is missing in type '{ email: string; }' but required in type 'User'.
Even though I return both id and email at the end, I am still facing errors during build process.