[SOLVED] Create email or using metamask

<!DOCTYPE html>

<html lang="en">

<!--

    1) AUTHENTICATE WITH METAMASK

    2) ADD USER TO DB

    3) ADD MORE DATA TO THE USER PROFILE

-->

  <head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="Width=device-width, initial-scale=1.0">

    <title>Document</title>

    <title>Metamask Demo</title>

    <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>

    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>

    <script src="main.js"></script>

  </head>

  <body>

    <input type="email" name="" id="email" placeholder="email">

    <input type="password" name="" id="password" placeholder="password">

    <button id="Signup">Sign up</button>

    <button onclick="login()">Login with Metamask</button>

    <script>

        Moralis.initialize("J6CBaLmgsnJr3m0AoQmInOLUK7ulCYf1Vdcz9A0v"); // Application id from moralis.io

        Moralis.serverURL = "https://u9h1idbhxxvh.moralishost.com:2053/server"; //Server url from moralis.io

        Moralis.authenticate({signingMessage:"welcome fitri"}) //custome message

    

        async function login(){

            console.log("login clicked");

            var user = await Moralis.Web3.authenticate();

            if(user){

                console.log(user);

                user.set("nickname","FITRI");

                user.set("fav_colour","hijau");

                user.save();

            }

        }

        Moralis.Web3.onAccountsChanged( async ([account])=>{

            alert("Do You Want To Merge?");

            var user = await Moralis.Web3.link(account);

            console.log(user)

        })

    

    </script>

  </body>

</html>

can someone help me what wrong with my code

const { sign } = require("crypto");

Moralis.initialize("J6CBaLmgsnJr3m0AoQmInOLUK7ulCYf1Vdcz9A0v");   // Application id from moralis.io

Moralis.serverURL = "https://u9h1idbhxxvh.moralishost.com:2053/server"; //Server url from moralis.io

init = async () => {

    window.web3 = await Moralis.Web3.enable();

    const user = await Moralis.User.current();

    console.log("user");

    console.log(user);

}

login = async () => {

    await Moralis.Web3.authenticate();

    const user = await Moralis.user.current();

    console.log("user");

    console.log(user);

}

signup = async (email, password,) =>{

        const user = new Moralis.User();

    user.set("username", email);

    user.set("password", password);

    user.set("email", email);

    try {

        await user.signUp();

        console.log("user");

        console.log(user);

    // Hooray! Let them use the app now.

    } catch (error) {

        // Show the error message somewhere and let the user try again.

         alert("Error: " + error.code + " " + error.message);

    }

}

logout = async () => await Moralis.User.logOut();

document.getElemetById("loginwithMetamask").onclick = login;

document.getElemetById("Signup").onclick = () => signup(document.getElemetById("email").value, document.getElemetById("password").value);

init();f

node js code

What is the problem that you have?

went i try create using email,at the server user cannot detect

like this but if i login with meta can

it looks like this part doesn’t work (loading/executing this main.js file) because you have const { sign } = require("crypto"); on first line and it results in the first error that you see in the console with require is not defined

so i need delete that line or need change it?

How is that you have that line there? I would say that you have to delete it, but I don’t know why it is there.

> <!DOCTYPE html>
> 
> <html lang="en">
> 
> <!--
> 
>     1) AUTHENTICATE WITH METAMASK
> 
>     2) ADD USER TO DB
> 
>     3) ADD MORE DATA TO THE USER PROFILE
> 
> -->
> 
>   <head>
> 
>     <meta charset="UTF-8">
> 
>     <meta http-equiv="X-UA-Compatible" content="IE=edge">
> 
>     <meta name="viewport" content="Width=device-width, initial-scale=1.0">
> 
>     <title>Metamask Demo</title>
> 
>     <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
> 
>     <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
> 
>     <script src="main.js"></script>
> 
>   </head>
> 
>   <body>
> 
>     <input type="email" name="" id="email" placeholder="email">
> 
>     <input type="password" name="" id="password" placeholder="password">
> 
>     <button id="Signup">Sign up</button>
> 
>     <button onclick="login()">Login with Metamask</button>
> 
>     <script>
> 
>         Moralis.initialize("J6CBaLmgsnJr3m0AoQmInOLUK7ulCYf1Vdcz9A0v"); // Application id from moralis.io
> 
>         Moralis.serverURL = "https://u9h1idbhxxvh.moralishost.com:2053/server"; //Server url from moralis.io
> 
>         Moralis.authenticate({signingMessage:"welcome fitri"}) //custome message
> 
>     
> 
>         async function login(){
> 
>             console.log("login clicked");
> 
>             var user = await Moralis.Web3.authenticate();
> 
>             if(user){
> 
>                 console.log(user);
> 
>                 user.set("nickname","FITRI");
> 
>                 user.set("fav_colour","hijau");
> 
>                 user.save();
> 
>             }
> 
>         }
> 
>         Moralis.Web3.onAccountsChanged( async ([account])=>{
> 
>             alert("Do You Want To Merge?");
> 
>             var user = await Moralis.Web3.link(account);
> 
>             console.log(user)
> 
>         })
> 
>     
> 
>     </script>
> 
>   </body>
> 
> </html>

maybe i wrong click btw this is my new code

Moralis.initialize("J6CBaLmgsnJr3m0AoQmInOLUK7ulCYf1Vdcz9A0v");   // Application id from moralis.io

Moralis.serverURL = "https://u9h1idbhxxvh.moralishost.com:2053/server"; //Server url from moralis.io

init = async () => {

    window.web3 = await Moralis.Web3.enable();

    const user = await Moralis.User.current();

    console.log("user");

    console.log(user);

}

login = async () => {

    await Moralis.Web3.authenticate();

    const user = await Moralis.User.current();

    console.log("user");

    console.log(user);

}

signup = async (email, password,) => {

        const user = new Moralis.User();

    user.set("username", email);

    user.set("password", password);

    user.set("email", email);

    try {

        await user.signUp();

        console.log("user");

        console.log(user);

    // Hooray! Let them use the app now.

    } catch (error) {

        // Show the error message somewhere and let the user try again.

         alert("Error: " + error.code + " " + error.message);

    }

}

logout = async () => await Moralis.User.logOut();

document.getElementById("loginwithMetamask").onclick = login;

document.getElementById("signup").onclick = () => signup(document.getElementById("email").value, document.getElementById("password").value);

init();f

i already correct some mistake can u check it?

I can not check now, it may be easier for you to understand what is there if you move all the JavaScript code from main.js in the html script part where you already have a JavaScript code that does the MetaMask authentication.

1 Like

ouh i see ok2 i will try btw thanks

can i ask you something where this code come from because at video he dont tell about this code


   <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js" ></script>
    <script src="https://unpkg.com/moralis/dist/moralis.js"></scrip

t>

Those lines are for web3 sdk and for Moralis sdk, don’t remove them.

1 Like

ouh i see thanks i just want know that hehe…btw problem already solved

1 Like

today i try login via metamask get alert like this

You can delete your user row from Users table and from _EthAddressTable table and then try again (in case that something happened with those rows)