Skip to content

Commit f123515

Browse files
committed
feat: add inline middleware for login and logout
1 parent 1c2c5a5 commit f123515

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pages/login.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
<script setup></script>
1+
<script setup>
2+
definePageMeta({
3+
middleware: function (to, from) {
4+
const isAuthenticated = useCookie('is-authenticated')
5+
const currentUser = useCookie('current-user')
6+
7+
if (isAuthenticated.value && currentUser.value) {
8+
return navigateTo('/profile/' + currentUser.value)
9+
}
10+
}
11+
})
12+
</script>
213

314
<template>
415
<article class="grid">

pages/logout.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
<script setup></script>
1+
<script setup>
2+
definePageMeta({
3+
middleware: function (to, from) {
4+
const isAuthenticated = useCookie('is-authenticated')
5+
const currentUser = useCookie('current-user')
6+
7+
isAuthenticated.value = ''
8+
currentUser.value = ''
9+
10+
return navigateTo('/')
11+
}
12+
})
13+
</script>
214

315
<template>
416
<article class="grid">

0 commit comments

Comments
 (0)