feat: implement auth middleware and protect review page route
This commit is contained in:
@@ -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')
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user