Hello guys, i had a code that worked with jsx, but now I'm on tsx and I have an error to resolve.
This error is in the declaration of my async function authorize(credentials) .
This is a big part of my code :
import GoogleProvider from "next-auth/providers/google";
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from "bcrypt";
import User from "@/app/(models)/User";
export const options = {
providers: [
GoogleProvider({
profile(profile) {
let userRole = "noroleuser";
if (profile?.email === "[email protected]") {
userRole = "Prov";
}
return {
...profile,
id: profile.sub,
role: userRole,
image: profile.picture,
};
},
clientId: process.env.GOOGLE_ID as string,
clientSecret: process.env.GOOGLE_Secret as string,
}),
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "email:",
type: "text",
placeholder: "email",
},
password: {
label: "mot de passe",
type: "password",
placeholder: "mot de passe",
},
},
async authorize(credentials) {
try {
const foundUser = await User.findOne({ email: credentials.email }).lean().exec();
if (foundUser) {
const match = await bcrypt.compare(credentials.password, foundUser.password);
if (match) {
delete foundUser.password;
foundUser["role"] = "Cred";
return foundUser;
}
}
} catch (err) {
console.log(err);
}
return null;
},
}),
],
// ( rest of the code )