Wallet + Email Auth at the same time

Hey guys,

I want to demand Email and Wallet Login at the same time, but it looks like that you can only use one at the same time. Is this true or did I just not find out how?

I analyzed the auth object, but I can not see any reference to the verification methods.

Can someone maybe clear my misunderstanding here?

I am using the react-moralis package inside NextJS.

Thank you

Hey, you can already do this but it will require steps on your part. As you already know we support both wallet authentication and email/sign up. To combine the two what you can do is on user logging in with metamask, you can query the user table to see if they have an email, if they don’t you make them provide, email, password, username before continuing. Upon doing that you can user moralis sign up to link the two. A simple version could look something like this

 async function login() {
            let user = Moralis.User.current();
            await Moralis.authenticate();
            user = Moralis.User.current();
            user.set("username", "my name");
            user.set("password", "my pass");
            user.set("email", "[email protected]");
            try {
              await user.signUp();
            } catch (error) {
              alert("Error: " + error.code + " " + error.message);
            }
        }

Hope this helps !

1 Like

How can I authenticate users with email alone. I have tried doing this but I keep getting errors. Thanks

this could help you:

https://v1docs.moralis.io/moralis-dapp/users/email-login

You can also try this to achieve such above

async function login() {
  try {
    // Email Signup
    let user = new Moralis.User();
    user.set("email", email);
    user.set("username", username);
    user.set("password", password);
    await user.signUp();

    // Connect ETH Account
    let web3 = await Moralis.enableWeb3();
    let signer = web3.getSigner();
    let account = await signer.getAddress();
    await Moralis.link(account);
  } catch (error) {
    console.log(error);
  }
}