feat: implement auth middleware and protect review page route

This commit is contained in:
Esa Kataja
2025-05-10 14:55:38 +03:00
parent fdbc7a2b23
commit 3203131f4a
2 changed files with 24 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
export default defineNuxtRouteMiddleware((to, from) => {
// Skip middleware if on server-side
// This is important because localStorage is only available client-side
if (process.server) return
// Check if user is logged in
const user = localStorage.getItem('user')
// If not logged in and trying to access a protected route
if (!user) {
// Redirect to login page
return navigateTo('/login')
}
})
+10
View File
@@ -1,4 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRuntimeConfig } from '#imports'
// Use definePageMeta to set auth middleware
definePageMeta({
middleware: 'auth'
})
const config = useRuntimeConfig()
const apiBase = config.public.apiBase
const { id } = useRoute().params const { id } = useRoute().params
interface Artist { interface Artist {