Skip to content

Commit

Permalink
less cls in main page and fixed auth refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tilalx committed Oct 13, 2024
1 parent f37414a commit f99af42
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<NuxtPage />
</NuxtLayout>
</VApp>
</template>
</template>
4 changes: 1 addition & 3 deletions app/components/layout/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,4 @@ const logoColor = computed(() => ({
const isLoggedIn = computed(() => loggedIn.value)
const drawer = ref(false)
</script>

<style scoped></style>
</script>
17 changes: 11 additions & 6 deletions app/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<template>
<NavBar :loggedIn="isLoggedIn" :settings="settings" />
<VMain>
<NuxtPage />
</VMain>
<v-main>
<v-container>
<NuxtPage />
</v-container>
</v-main>

<FootBar :settings="settings" />
</template>

Expand Down Expand Up @@ -38,7 +41,7 @@ const getSettings = async () => {
const refreshSession = async () => {
try {
await pb.authStore.refresh()
await pb.collection('users').authRefresh()
isLoggedIn.value = pb.authStore.isValid
} catch (error) {
isLoggedIn.value = false
Expand All @@ -49,7 +52,9 @@ const refreshSession = async () => {
const setFavicon = () => {
if (!settings.value?.page_icon) return
const favUrl = pb.files.getUrl(settings.value, settings.value.page_icon)
let link = document.querySelector("link[rel~='icon']") || document.createElement('link')
let link =
document.querySelector("link[rel~='icon']") ||
document.createElement('link')
link.rel = 'icon'
link.href = favUrl
document.head.appendChild(link)
Expand All @@ -64,7 +69,7 @@ onMounted(async () => {
settings.value = await getSettings()
await refreshSession()
setFavicon()
intervalId = setInterval(checkSession, 600)
} catch (error) {
// Handle error (e.g., display notification to user)
Expand Down
25 changes: 14 additions & 11 deletions app/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { usePocketbase } from '#imports'

export default defineNuxtRouteMiddleware(async (to, from, next) => {
export default defineNuxtRouteMiddleware(async (to, from) => {
// Ensure the middleware runs only on the client side
if (process.client) {
const authRequired = to.meta.authRequired || true

const pb = usePocketbase()

// Retrieve the current session from Supabase
// Retrieve the current session from Pocketbase
const isValidSession = pb.authStore.isValid

if (authRequired && to.path !== '/') {
if (!isValidSession) {
// If the session is not valid, redirect to the login page
return navigateTo('/login')
}
if (to.name === 'Login' && isValidSession) {
// Redirect to the dashboard if already logged in and trying to access the login page
return navigateTo('/dashboard')
}
if (!isValidSession) {
// If the session is not valid, redirect to the login page
return navigateTo('/login')
}

if (to.name === 'Login' && isValidSession) {
// Redirect to the dashboard if already logged in and trying to access the login page
return navigateTo('/dashboard')
}
}
}
})
7 changes: 2 additions & 5 deletions app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useI18n, useHead } from '#imports'
import RouteDetails from '@/components/RouteDetails.vue'
const { t } = useI18n()
useHead({
Expand Down Expand Up @@ -166,12 +162,13 @@ const fetchClimbingRoutes = async () => {
}
const getClimbingRoutes = async () => {
await fetchClimbingRoutes()
pb.collection('routes').subscribe('*', function () {
getClimbingRoutes()
})
}
await fetchClimbingRoutes()
onMounted(() => {
getClimbingRoutes()
})
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default defineNuxtConfig({
cookieName: 'color-scheme', // Stores user's preferred color scheme
useBrowserThemeOnly: true, // Strictly uses the browser theme without relying on cookies
},
prefersReducedMotion: true, // Uses Sec-CH-Prefers-Reduced-Motion for reduced motion detection
}
},
vuetifyOptions: {
Expand Down

0 comments on commit f99af42

Please sign in to comment.