[SOLVED] Adding users by metamask using react JS


I’m trying to add users by metamask address and add a role to each user, my problem is, after i add the user and save it in moralis database, when i trying to connect with that user, he can’t identifier that the user already exists in moralis database and it will create a new account for that user !

the code to add new user by metamask address
try {
const _user = new Moralis.User();
_user.set(“ethAddress”, data.metamask_address)
await _user.signUp();
} catch (error) {

              console.log("error ===>",error)

I don’t know if it was suppose to work like that, it also should validate somehow the eth address

The eth address i take it from the user it self, the user give me his eth address , and my job as admin of plateforme is to add this user to moralis database and give him a role (admin/user)

You can try without setting the eth address, only username, email, password. And later the user can use .link to add the eth address

ok but when i send link to the user, how i can update the row in the moralis database and add the eth address ?! my problem in the previous code that when the user try to connect , even his metamask exists in moralis db he add new row

I mean, the user can connect initially with email and password, and then he can use Moralis.link(eth_address), MetaMask will pop up and that eth address should be associated with that user account after that

Ok I will try it thank u !

Thank you it works !

1 Like