Hi guys, I was following the tutorial âConnect to a Database with Web3 Authentication | MongoDB, NextJS and Moralisâ. However, the information sent to MongoDB, in this tutorial, is from the âsigninâ page, and I would like to, instead of using the information from that page, send to the database the information generated in the âprotectedâ page as âNftlistâ. Because I am creating my Dapp using the nft-gating template, and there is a âprotectedâ page. I would like to get the user information generated on that page(protected page) to send to my database.
I am trying to do it this way:
export async function getServerSideProps(context) {
const session = await getSession(context);
if (!session) {
return {
redirect: {
destination: '/signin',
permanent: false,
},
};
}
await Moralis.start({ apiKey: process.env.MORALIS_API_KEY });
const nftList = await Moralis.EvmApi.account.getNFTsForContract({
address: session.user.address,
tokenAddress: âxxxxxâ,
chain: 1
});
await connectDB();
const MongoUser = await Users.findOne({owner_of: owner_of}, {token_id: token_id}, {block_number: block_number}, {token_address: token_address}, {token_hash: token_hash})
if(!MongoUser){
const newUser = new Users({
profileId: profileId
})
await newUser.save();
}
return {
props: {
message:
// if user has at least one NFT he will get protected content
nftList.raw.total > 0 ? 'Nice! You have our NFT' : "Sorry, you don't have our NFT",
nftList: nftList.raw.result,
},
};
}
export default Protected;
But I am getting this error:
And I donât know what I am doing wrong since the constant Nftlist has this following attributes:
Could someone help me with this? How can I send these attributes generated by this âNftlistâ to my database when the user enters this page?