so in my authorize function in nextAuth , when checking valid information of the i get a {} , then i get the user object however and this has led to enter the opposite condition first than access the condition after r=getting user object , the api endpoint is doing well , i assumed that this problem has a relation to async/await function it may return {} until it get the data , any suggestions ?
//my credentials code
CredentialsProvider({
name: "Credentials",
credentials: {
email: {},
password: {}
},
async authorize(credentials, req) {
// Add logic here to look up the user from the credentials supplied
try{
// const res = await getUserCredentials(credentials?.email as string, credentials?.password as string)
// const res = await fetch("http://localhost:3000/api/login",{
// method:"POST",
// headers:{
// "Content-type":"application/json"
// },
// body:JSON.stringify({
// email:credentials?.email,
// password: credentials?.password
// })
// })
const res = await fetch("http://localhost:3000/api/login",{
method:"POST",
headers:{
"Content-type":"application/json"
},
body:JSON.stringify({
email:credentials?.email,
password: credentials?.password
})
}).then((response)=>response.text())
.then((result)=>console.log(result))
.catch((error)=>console.log(error))
const isEmpty = (obj:any) => {
return Object.keys(obj).length === 0;
};
const user = await res;
console.log(user+'bbb');
// if (!res.ok) {
// console.error("Invalid credentials provided");
// return null;
// }
// if (res) {
// console.log("User authenticated:", user);
// console.log("this is user : " , user)
// return user;
// }
// console.error("User not found or invalid response:", user);
// return null;
return null
} catch (error) {
console.error("Error during user authentication:", error);
return null;
}
}
}),
],
callbacks: {
async jwt({ token, user }) {
return { ...token, ...user };
},
async session({ session, token, user }) {
session.user = token as any;
return session;
},
},
New contributor
Yasser is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.