Yay let's go we have a functioning frontend

This commit is contained in:
Ada Werefox 2025-04-23 10:22:53 -07:00
parent d8e7e34b83
commit 426542d4c9
3 changed files with 41 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import UserDashboard from '@/views/UserDashboard.vue'
import { isLoggedIn } from '@/ts/authorization'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -9,13 +10,37 @@ const router = createRouter({
path: '/',
name: 'home',
component: HomeView,
beforeEnter: (to) => {
isLoggedIn().then((response) => {
if (response) {
const redirect = to.query.redirect?.toString()
if (redirect != undefined) {
router.replace(redirect)
} else {
router.replace('/dashboard')
}
}
})
},
meta: { requiresAuth: false },
},
{
path: '/dashboard',
name: 'user-dashboard',
component: UserDashboard,
meta: { requiresAuth: true },
},
],
})
router.beforeEach((to) => {
if (to.meta.requiresAuth) {
isLoggedIn().then((response) => {
if (response == false) {
router.replace('/?redirect=' + to.fullPath)
}
})
}
})
export default router

15
src/ts/authorization.ts Normal file
View file

@ -0,0 +1,15 @@
export function isLoggedIn(): Promise<boolean> {
return fetch('http://localhost:31337/authorized', {
credentials: 'include',
})
.then((res) => {
return res.json().then((res_json) => {
const is_authorized = res_json.message
console.log('whwhwhw' + is_authorized)
return Boolean(is_authorized)
})
})
.catch(() => {
return false
})
}

View file

@ -26,7 +26,7 @@ onMounted(update_info)
</div>
<a
class="flex w-full p-2 font-mono text-lg md:p-4 md:text-2xl bg-secondary ring-2 ring-secondary/80 h-fit0 hover:bg-secondary/50"
href="logout"
href="http://localhost:31337/logout"
>
<div class="w-full h-full text-center bg-primary">
<p class="drop-shadow-accent drop-shadow-md">Logout</p>