<template>
  <div class="flex flex-center">
    <LoginForm v-on:update-close="forwardToPage" />
  </div>
</template>

<script setup lang="ts">
import { getLocalLastRoute } from 'src/localstorage/localStorage';
import LoginForm from 'src/vueLib/login/LoginForm.vue';
import { useUserStore } from 'src/vueLib/login/userStore';
import { nextTick, onMounted } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const userStore = useUserStore();

onMounted(() => {
  if (userStore.user?.username !== '' && userStore.user?.role !== '') {
    forwardToPage().catch((err) => console.error(err));
  }
});

const forwardToPage = async () => {
  await nextTick();
  await router.push(getLocalLastRoute());
};
</script>
