[SOLVED] Logout function not working

Moralis.start({ serverUrl, appId });

async function login() {

let user = Moralis.User.current();

if (!user) {

    user = await Moralis.authenticate();

}

console.log("logged in user:", user);

}

async function logOut() {

await Moralis.User.logOut();

console.log("logged out");

}

document.getElementById(“btn-login”).onclick = login;

document.getElementById(“btn-logout”).onclick = logOut;

what error do you get? what happens? did you set proper serverUrl and appId?

Yes i can login successfully but i couldn’t logout

can you share your entire html source code + js?

You can see here how to post code: READ BEFORE POSTING - How to post code in the forum

const serverUrl = "https://mzrhanzmogsu.moralishost.com:2053/server/server";
const appId = "gFnTLmvgt8ZDUYMXF80FIonsCRqosKxXcfzmO2bM";

Moralis.start({ serverUrl, appId });
async function login() {
    let user = Moralis.User.current();
    if (!user) {
        user = await Moralis.authenticate();
    }
    console.log("logged in user:", user);
}

async function logOut() {
    await Moralis.User.logOut();
    console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;```
1 Like
<html>

<head>
    <title>MrGrandpadoge NFT Marketplace</title>

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

<body>

    <h1>MrGrandpadoge NFT Marketplace</h1>

    <button id="btn-login">Login</button>
    <button id="btn-logout">Logout</button>

</body>


</html>

it looks like it is a problem with your server, can you restart/update your server?

Please is the version am using correct in the html script?

The html should be like this:

<html>

<head>
    <title>MrGrandpadoge NFT Marketplace</title>

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

</head>

<body>

    <h1>MrGrandpadoge NFT Marketplace</h1>

    <button id="btn-login">Login</button>
    <button id="btn-logout">Logout</button>
    <script src="main.js"></script>
</body>

but there seems to be a problem with your Moralis server, can you update your Moralis server from admin interface?

okay let me update that

When i click on logout button, it won’t pop up on my screen whereas when i click on login, it will pop up on my screen for me to sign in

logout button will not pop up anything when it works, will only write logged out in your browser console.
even if you see that pop up for login, it doesn’t mean that it really worked completely.

1 Like

Thanks you solved my issue

But the tutorial on how to clone rarible in 24 hours is outdated source code

you should have here const serverUrl = "https://mzrhanzmogsu.moralishost.com:2053/server"; instead of what you have there

Yes, that tutorial has some outdated syntax as a lot of things changed in last few months here.

Where can i get the updated sythax?

you already use the updated syntax with Moralis.start({ serverUrl, appId }); in this example.

What i mean is that i was trying to follow the procedure of the Rarible NFT clone which i was using that to practice my skills. Since you said there’s a lot of changes since then, so if i have any problem with it, i will definitely send a report here