mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-03-11 11:55:38 +00:00
Fix: Add localStorage fallback for Plex authentication checks
Issue: ActivityPage and route guards showed "not authenticated" even when Plex was linked via Settings page. Root cause: Plex user data stored in localStorage but route guards and ActivityPage only checked Vuex store (state.settings.plexUserId). Changes: - Update routes.ts hasPlexAccount() to check both: 1. Vuex store (user/plexUserId) 2. localStorage (plex_user_data) as fallback - Update ActivityPage plexUserId computed to check both: 1. Vuex store first 2. localStorage plex_user_data.id as fallback Why two sources? - Vuex store: Set from JWT token (backend user settings) - localStorage: Set immediately when linking Plex account - localStorage persists across page reloads - Provides seamless experience without backend round-trip Now Activity page correctly shows data when Plex is linked ✓
This commit is contained in:
@@ -132,7 +132,25 @@
|
|||||||
|
|
||||||
const days: Ref<number> = ref(30);
|
const days: Ref<number> = ref(30);
|
||||||
const graphViewMode: Ref<GraphTypes> = ref(GraphTypes.Plays);
|
const graphViewMode: Ref<GraphTypes> = ref(GraphTypes.Plays);
|
||||||
const plexUserId = computed(() => store.getters["user/plexUserId"]);
|
|
||||||
|
// Check both Vuex store and localStorage for Plex user
|
||||||
|
const plexUserId = computed(() => {
|
||||||
|
// First try Vuex store
|
||||||
|
const storeId = store.getters["user/plexUserId"];
|
||||||
|
if (storeId) return storeId;
|
||||||
|
|
||||||
|
// Fallback to localStorage
|
||||||
|
const userData = localStorage.getItem("plex_user_data");
|
||||||
|
if (userData) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(userData).id;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
const plexUsername = computed(() => {
|
const plexUsername = computed(() => {
|
||||||
const userData = localStorage.getItem("plex_user_data");
|
const userData = localStorage.getItem("plex_user_data");
|
||||||
if (userData) {
|
if (userData) {
|
||||||
|
|||||||
@@ -102,7 +102,22 @@ const router = createRouter({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const loggedIn = () => store.getters["user/loggedIn"];
|
const loggedIn = () => store.getters["user/loggedIn"];
|
||||||
const hasPlexAccount = () => store.getters["user/plexUserId"] !== null;
|
const hasPlexAccount = () => {
|
||||||
|
// Check Vuex store first
|
||||||
|
if (store.getters["user/plexUserId"] !== null) return true;
|
||||||
|
|
||||||
|
// Fallback to localStorage
|
||||||
|
const userData = localStorage.getItem("plex_user_data");
|
||||||
|
if (userData) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(userData);
|
||||||
|
return parsed.id !== null && parsed.id !== undefined;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
const hamburgerIsOpen = () => store.getters["hamburger/isOpen"];
|
const hamburgerIsOpen = () => store.getters["hamburger/isOpen"];
|
||||||
|
|
||||||
router.beforeEach(
|
router.beforeEach(
|
||||||
|
|||||||
Reference in New Issue
Block a user