Skip to content

A self-hosted media server and file management system

fix navbar auth state missing on new page load

aminnausin3751e19d223b
diff --git a/resources/js/components/layout/NavBar.vue b/resources/js/components/layout/NavBar.vue
index e0a567a5..3aada597 100644
--- a/resources/js/components/layout/NavBar.vue
+++ b/resources/js/components/layout/NavBar.vue
@@ -1,7 +1,7 @@
<script setup>
import { storeToRefs } from 'pinia';
import { useAuthStore } from '../../stores/AuthStore'
- import { ref, onMounted } from 'vue';
+ import { ref, onMounted, watch } from 'vue';
import { RouterLink } from 'vue-router';
import UserDropdown from '../user/UserDropdown.vue';
@@ -25,42 +25,46 @@
}
});
+ const handleAuthEvent = (newUserData) => {
+ username.value = newUserData?.name ?? '';
+ }
onMounted(async () => {
- await auth();
- username.value = userData.value?.name ?? '';
+ if(await auth()) handleAuthEvent(userData.value)
})
+
+ watch(userData, handleAuthEvent, {immediate: false});
</script>
<template>
<nav id="navbar">
<div class="flex p-1 gap-y-3 flex-wrap justify-between">
<h1 id="title" class="text-2xl">{{ pageTitle }}</h1>
- <span class="flex flex-wrap sm:flex-nowrap sm:max-w-sm items-center gap-2 sm:shrink-0">
+ <span class="flex flex-wrap sm:flex-nowrap sm:max-w-sm items-center gap-2 sm:shrink-0">
<section id="user_options" class="group inline-block relative" data-dropdown-toggle="user_dropdown" aria-haspopup="true">
- <button id="user_header" class="flex space-x-2 text-2xl text-slate-900 dark:text-white hover:text-orange-600 dark:hover:text-orange-600 items-center justify-center" @click="toggleDropdown">
+ <button id="user_header" class="flex gap-2 text-2xl text-slate-900 dark:text-white hover:text-orange-600 dark:hover:text-orange-600 items-center justify-center" @click="toggleDropdown">
<span id="user_name" v-if="username">{{ username }}</span>
<span id="user_name_unauth" v-else class="w-[10vw] text-right">Guest</span>
- <img :src="userData?.value?.avatar ?? '/storage/avatars/12345.jpg'" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg object-cover" alt="profile picture">
+ <img :src="userData?.value?.avatar ?? '/storage/avatars/12345.jpg'" class="h-7 w-7 rounded-full ring-2 ring-orange-600/60 object-cover aspect-square" alt="profile picture">
</button>
<UserDropdown v-if="showDropdown"/>
</section>
- <section id="navbar-video" class="flex items-center space-x-2">
+ <section id="navbar-video" class="flex items-center gap-1">
<button v-if="$route.name === 'home'" id="btn-nav-folders" @click="cycleSideBar('folders')" class="flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-red-300 hover:bg-red-200" aria-label="folders">
<svg xmlns="https://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" height="24" width="24" class="stroke-slate-900">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 9.776c.112-.017.227-.026.344-.026h15.812c.117 0 .232.009.344.026m-16.5 0a2.25 2.25 0 0 0-1.883 2.542l.857 6a2.25 2.25 0 0 0 2.227 1.932H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-1.883-2.542m-16.5 0V6A2.25 2.25 0 0 1 6 3.75h3.879a1.5 1.5 0 0 1 1.06.44l2.122 2.12a1.5 1.5 0 0 0 1.06.44H18A2.25 2.25 0 0 1 20.25 9v.776" />
</svg>
</button>
- <button v-if="userData && $route.name === 'home'" id="btn-nav-history" @click="cycleSideBar('history')" class="flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-purple-300 hover:bg-purple-200" aria-label="watch history">
+ <button v-if="username && $route.name === 'home'" id="btn-nav-history" @click="cycleSideBar('history')" class="flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-purple-300 hover:bg-purple-200" aria-label="watch history">
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="24" width="24" class="fill-slate-900">
<path d="M0 0h24v24H0z" fill="none" />
<path fill-rule="evenodd" d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" />
</svg>
</button>
- <button v-if="userData" id="btn-nav-notifications" @click="cycleSideBar('notifications')" class="hidden justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-red-300 hover:bg-red-200" aria-label="notifications">
+ <button v-if="username" id="btn-nav-notifications" @click="cycleSideBar('notifications')" class="hidden justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-red-300 hover:bg-red-200" aria-label="notifications">
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="24" width="24" class="fill-slate-900">
<path fill-rule="evenodd" d="M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z" clip-rule="evenodd" />
</svg>
@@ -72,12 +76,12 @@
</RouterLink>
</section>
- <div class="toggle-switch shrink-0">
+ <section class="toggle-switch shrink-0">
<label class="switch-label">
<input type="checkbox" class="checkbox invisible" id="dark-mode-toggle" @click="toggleDarkMode(false)" v-bind:checked="!darkMode">
<span class="slider"></span>
</label>
- </div>
+ </section>
</span>
</div>
<hr class="mt-2 mb-3">