<%- include ("./partials/header") %>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<div id="info">Hoi!</div>
<a id="login" style="display: none;" href="https://discord.com/api/oauth2/authorize?client_id=1068936253317320785&redirect_uri=https%3A%2F%2F127.0.0.1%3A8000%2F&response_type=code&scope=identify">Identify Yourself</a>
<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) {
			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 } = response;
				document.getElementById('info').innerText += ` ${username}#${discriminator}`;
			})
			.catch(console.error);
	};
</script>
<%- include ("./partials/footer") %>