<script>
    import { onMount } from 'svelte';
    import { member, intros } from './store.ts';

    const authorizeUri = "https://discord.com/api/oauth2/authorize?client_id=577634620728934400&redirect_uri=https%3A%2F%2Fspacegirl.nl%2Fmemes%2Fauth&response_type=code&scope=guilds.members.read%20guilds%20identify";

    onMount(async () => {
        const token = window.localStorage.getItem('token');

        if (!!token) {
            await member.pullData(token);
            await intros.fetchIntros($member.guilds);
        }
    }); 

    const login = async (username) => {
        window.location = authorizeUri;
    }

    let loginPromise = null;

    let enteredUsername = '';
</script>

<p style="color:red;">You need to login first</p>
<button on:click={() => loginPromise = login(enteredUsername)}>Login</button>
