I just tried the solution and got the same error
I donât know if this information can help in solving this problem, but when I try to put it âConnectDBâ inside the function triggered by the button, I also get an error, which is this one below:
And to try to make myself clearer, in that case the code would look like this with the âConnectDBâ function inside the trigger and not inside the âgetServerSidePropsâ function:
...
try {
connectDB ();
const userResult = await response.raw.result.find( (owner) => owner.owner_of == onwerad );
console.log(userResult);
const { Users } = require('../lib/userSchema')
const owner_of = userResult.owner_of
const token_id = userResult.token_id
const amount = userResult.amount
console.log(owner_of, token_id, amount);
console.log("ok");
const MongoUser = await Users.exists({owner_of: owner_of});
if (!MongoUser) {
const newUser = new Users({
owner_of: owner_of,
token_id: token_id,
amount: amount,
})
await newUser.save();
console.log("everything works fine");
}
return user;
...