<script setup lang="ts">
  import { onMounted } from "vue";
  import { checkIfLoggedIn } from "@/helpers/api.ts";
  import { useRouter } from "vue-router";
  import Uploader from "@/components/Uploader.vue";
  import FileList from "@/components/FileList.vue";

  const router = useRouter();
  
  onMounted(async () => {
    const loggedIn = await checkIfLoggedIn();
    if (!loggedIn) {
      await router.push('/login');
      return;
    }
  });
  
  const logout = async () => {
    await fetch('/api/user/logout');
    window.location.reload();
  };
</script>

<template>
  <FileList />
  <Uploader />
  <a href="#" v-on:click.prevent="logout">Log out</a>
</template>

<style scoped>

</style>