mrowlsss @mrowlsss

what the fuck

mrowlsss @mrowlsss

I’m still working on wasteof.money for snap(.berkeley), but because I know how to use the wasteof api, I have came to the realization that I now have to create a mod with custom blocks (which i am very skilled at)

Nov 11, 2023, 1:21 PM
3
Nov 11, 2023, 2:23 PM
24
View all Parent

comments

Highlighted comment

You’re returning a promise there, that’s told to get the text when its done. You’d have to put the alert inside the then statement, so it only gets called when the promise is actually done. There’s a lot of callback hell involved with dealing with promises as they are. async/await solves a lot of that. I’d recommend reading more about promises to understand what they are and how they work: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

wait rq can you give me an example of using async/await with this?

const token = await (await fetch(...)).text;

And the function it's wrapped in has to be async, e.g.

// my favorite
const func = async () => {}
// or
const func = async function() {}
// or
async function func() {}

i tried

            const token = await (await fetch("https://api.wasteof.money/session", requestOptions).text;
     		alert(token);

and it isnt working, am i doing something wrong?

The brackets are unmatched, but apart from that, that should work. What's the error you're getting?

i am not getting any console error, nor the test alert i have put in, which is making me think previous js code is making it not work. here is my entire html doc, can you tell me what’s wrong?

<!doctype HTML>

<head>

</head>

<html>

<body>

<script src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js" crossorigin="anonymous"></script>

<script>

window.onload = function() {

// Parses the document body and

// inserts <img> tags in place of Unicode Emojis

twemoji.parse(document.body, {

folder: 'svg',

ext: '.svg'

} // This is to specify to Twemoji to use SVGs and not PNGs

);

}

</script>

<style>

img.emoji {

width: 1.5em;

pointer-events: none;

}

</style>

<script>

var myHeaders = new Headers();

myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({

"username": "mrowlsss",

"password": "pass123donthackme"

});

var requestOptions = {

method: 'POST',

headers: myHeaders,

body: raw,

redirect: 'follow'

};

alert("a");

const token = await (await fetch("https://api.wasteof.money/session", requestOptions)).text;

alert(token);

</script>

</body>

</html>

See more replies

actually, better and easier option, can you just give me code that will alert the response of the fetch?