czypher_
czypher_
DIAdiscord.js - Imagine an app
Created by czypher_ on 7/22/2024 in #djs-questions
"CORS" dashboard issue.
Alright.
7 replies
DIAdiscord.js - Imagine an app
Created by czypher_ on 7/22/2024 in #djs-questions
"CORS" dashboard issue.
Alrighty, do I just post the samemessage in there.
7 replies
DIAdiscord.js - Imagine an app
Created by czypher_ on 7/22/2024 in #djs-questions
"CORS" dashboard issue.
Sorce Codes: / images Dashboard.HTML
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="/">
<link rel="stylesheet" type="text/css" href="output.css" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="flex items-center justify-center h-screen bg-discord-gray text-white flex-col">
<div class="text-2xl">Welcome to the dashboard,</div>
<div class="text-4xl mt-3 flex items-center font-medium" >
<img src='' id="avatar" class="rounded-full w-12 h-12 mr-3"/>
<div id="name"></div>
</div>
<a href="/" class="text-sm mt-5">Logout</a>
</div>


<script>

window.onload = () => {
const fragment = new URLSearchParams(window.location.hash.slice(1));
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];

if (!accessToken) {
window.location.href('/')
return (document.getElementById('login').style.display = 'block');
}

fetch('https://discord.com/api/users/@me', {
headers: {
authorization: `${tokenType} ${accessToken}`,
},

})
.then(result => result.json())
.then(response => {


const { username, discriminator, avatar, id} = response;
//set the welcome username string
document.getElementById('name').innerText = ` ${username}#${discriminator}`;

//set the avatar image by constructing a url to access discord's cdn
document.getElementById("avatar").src = `https://cdn.discordapp.com/avatars/${id}/${avatar}.jpg`;

})
.catch(console.error);

};

</script>


</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="/">
<link rel="stylesheet" type="text/css" href="output.css" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="flex items-center justify-center h-screen bg-discord-gray text-white flex-col">
<div class="text-2xl">Welcome to the dashboard,</div>
<div class="text-4xl mt-3 flex items-center font-medium" >
<img src='' id="avatar" class="rounded-full w-12 h-12 mr-3"/>
<div id="name"></div>
</div>
<a href="/" class="text-sm mt-5">Logout</a>
</div>


<script>

window.onload = () => {
const fragment = new URLSearchParams(window.location.hash.slice(1));
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];

if (!accessToken) {
window.location.href('/')
return (document.getElementById('login').style.display = 'block');
}

fetch('https://discord.com/api/users/@me', {
headers: {
authorization: `${tokenType} ${accessToken}`,
},

})
.then(result => result.json())
.then(response => {


const { username, discriminator, avatar, id} = response;
//set the welcome username string
document.getElementById('name').innerText = ` ${username}#${discriminator}`;

//set the avatar image by constructing a url to access discord's cdn
document.getElementById("avatar").src = `https://cdn.discordapp.com/avatars/${id}/${avatar}.jpg`;

})
.catch(console.error);

};

</script>


</body>
</html>
Picture of error(s):
7 replies