Hi!
Iām trying to save the userās email after login with magic link. Iāve tried multiple ways, but nothing seems to work. What I have tried:
1.with user after login
const loginWithMagicLink = async () =>{
await authenticate({
provider:"magicLink",
email:email,
apiKey:"my_pk",
network: customeNodeOptions
}).then(async (user) => {
user.set("email", email)
await user.save()
})
.catch(function (error) {
console.log(error);
});
}
it will return null user
2. with Moralis.User.current()
const loginWithMagicLink = async () =>{
await authenticate({
provider:"magicLink",
email:email,
apiKey:"my_pk",
network: customeNodeOptions
}).then(async () => {
const user = Moralis.User.current()
user.set("email", email)
await user.save()
})
.catch(function (error) {
console.log(error);
});
}
throws error āclient itās not allowed to maually update email verificationā
3. cloud function
const loginWithMagicLink = async () =>{
await authenticate({
provider:"magicLink",
email:email,
apiKey:"my_pk",
network: customeNodeOptions
}).then(async (user) => {
const params = {objectId:userId, email:email}
await Moralis.Cloud.run("setUserEmail", params)
})
.catch(function (error) {
console.log(error);
});
}
throws error āresult.set()ā is not a function or ācannot read properties of undefinedā
this is the cloud function:
Moralis.Cloud.define("setUserEmail", async(request) =>{
const query = new Moralis.Query("User")
await query.equalTo("objectId", request.params.userId)
const result = await query.first()
result.set("email", request.params.email)
const logger = Moralis.Cloud.getLogger()
logger.info(result)
return result.save({useMasterKey:true})
})
Am I missing something? Any help would be appreciated!