check auth on mount
This commit is contained in:
parent
5069965ba3
commit
bdd0990922
3 changed files with 48 additions and 3 deletions
18
app/middleware/auth.global.js
Normal file
18
app/middleware/auth.global.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
const publicRoutes = ['/oauth']
|
||||
|
||||
if (publicRoutes.includes(to.path)) {
|
||||
return
|
||||
}
|
||||
|
||||
const { isAuthenticated, verifySession, isInitialized } = useAuth()
|
||||
|
||||
if (!isInitialized.value) {
|
||||
await verifySession()
|
||||
}
|
||||
|
||||
//whats the shape of Italy?
|
||||
if (!isAuthenticated.value) {
|
||||
return navigateTo('/oauth', { replace: true })
|
||||
}
|
||||
})
|
||||
20
app/pages/[...slug].vue
Normal file
20
app/pages/[...slug].vue
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
const { isAuthenticated, verifySession } = useAuth()
|
||||
|
||||
onMounted(async () => {
|
||||
const valid = await verifySession()
|
||||
if (!valid || !isAuthenticated.value) {
|
||||
await navigateTo('/oauth', { replace: true })
|
||||
} else {
|
||||
await navigateTo('/', { replace: true })
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #0d1117;">
|
||||
<span class="spinner sm"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
|
||||
const { userToken } = useAuth()
|
||||
const { userToken, isAuthenticated, verifySession } = useAuth()
|
||||
|
||||
const sfidInput = ref('')
|
||||
const step = ref(1)
|
||||
|
|
@ -11,6 +11,13 @@ const isSearching = ref(false)
|
|||
const isSubmitting = ref(false)
|
||||
const errorMessage = ref('')
|
||||
|
||||
onMounted(async () => {
|
||||
const valid = await verifySession()
|
||||
if (!valid || !isAuthenticated.value) {
|
||||
await navigateTo('/oauth', { replace: true })
|
||||
}
|
||||
})
|
||||
|
||||
const handleLookup = async () => {
|
||||
if (!sfidInput.value.trim()) return
|
||||
|
||||
|
|
@ -62,7 +69,7 @@ const handleReset = () => {
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<div class="login-wrapper">
|
||||
<div v-if="isAuthenticated" class="login-wrapper">
|
||||
<section class="settings-panel" style="max-width: 480px; margin: 0 auto;">
|
||||
<div class="panel-header archivo-black">
|
||||
WELCOME
|
||||
|
|
|
|||
Loading…
Reference in a new issue