[react-moralis] non crypto login opens metamask

According to documentation
const { login } = useMoralis();
is for non crypto login
but this opens up Metamask

Could you pinpoint to the documentation article so that I can check it out?

Thanks.

Under the header login() (non-crypto)

Can you share a code snippet on how/where you implement this function?
Also when does it open metamask?

  • right away?
  • when calling the login function?
  • after a successful login?

I have a form

      <Form onSubmit={onLogin}>
        <Button type='submit'>Login</Button>
      </Form>

so when user clicks β€˜Login’, funciton onLogin is called

  const { login } = useMoralis();

  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");
  const [errorMsg, setErrorMsg] = useState("");

  const onLogin = (event) => {
    event.preventDefault();

    login(username, password)
      .then(() => {
        setErrorMsg("");
        history.push("/");
      })
      .catch((err) => {
        console.error("Error signing in.", err);
        setErrorMsg(err.toString());
      });
  };

and Metamask opens immediately after I click the Login button

1 Like

Ok, I found the bug. It is caused by web.enable that gets called after a user is successfully authenticated (done by react-moralis). This will open up Metamask to log you in if you are not logged into Metamask yet. Note: it will not ask you to sign a transaction, but a logged-in Metamask is needed, so it can serve as a web3 provider.

This is fixed in v0.1.8.

We are not enabling web3 by default on login anymore. (you need to enable web3 manually if you want to use web3 functionalities. See the Readme)

3 Likes