Iām calling a Cloud function from one of my API routes and Iām having an issue where itās not finding the ethAddress of user. Iām trying to switch a userās āemailVerifiedā value but getting "error": "user.set is not a function"
returned from the route.
It looks like .find()
isnāt matching anything but it should.
The logger results below:
Logs..
shows:
Logs...{"params":{"_ApplicationId":"XPL7i7UbHjQQINxEFpY8eRLk7LM2EtdoyF8Vdhdq","ethAddress":"0x9396c0fed2af8257f59437f461de1c8ff7b066301","changeVerified":"true","unsetVerifyToken":"true"},"master":false,"functionName":"switchUserVerified","context":{}}
ethAddress... returns the correct address
User | Query: {"where":{"ethAddress":"0x9.......01"}}
User: []
Not sure where Iām going wrong here?
Moralis.Cloud.define('switchUserVerified', async (request) => {
const logger = Moralis.Cloud.getLogger();
logger.info('Logs...' + JSON.stringify(request));
logger.info('ethAddress...' + JSON.stringify(request.params.ethAddress));
const User = Moralis.Object.extend('_User');
const query = new Moralis.Query(User);
query.equalTo('ethAddress', request.params.ethAddress);
logger.info(`User | Query: ${JSON.stringify(query)}`);
const user = await query.find({ useMasterKey: true });
logger.info(`User: ${JSON.stringify(user)}`);
user.set('emailVerified', changeVerifiedBool);
user.unset('verifyToken');
logger.info('Saving user...');
await user.save(null, { useMasterKey: true });
});
This is how Iām calling the Cloud function from Next.js API route:
const response = await fetch(
`https://46664sqdmacoh.usemoralis.com:2053/server/functions/switchUserVerified?_ApplicationId=${appId}ðAddress=${address}&changeVerified=${changeVerifiedBool}&unsetVerifyToken=${changeVerifiedBool}`,
{
method: 'POST',
}
);
const data = await response.json();