<script setup lang="ts">
import { inject, onBeforeMount } from 'vue'
import { RouterView, useRouter } from 'vue-router'
import type { AuthenticationService } from './services/AuthenticationService'
import { useAuthStore } from '@/stores/auth'
import { storeToRefs } from 'pinia'

const authStore = useAuthStore()
const { isLoggedIn } = storeToRefs(authStore)
const auth: AuthenticationService = inject<AuthenticationService>('auth') as AuthenticationService
const router = useRouter()

async function checkLoggedIn() {
  await auth.fromStorage()
  if (isLoggedIn.value) {
    router.push('home')
  }
}

onBeforeMount(checkLoggedIn)
</script>

<template><RouterView /></template>

<style scoped></style>
