diff --git a/frontend/src/stores/dashboard.ts b/frontend/src/stores/dashboard.ts index 7f7f828..2fea428 100644 --- a/frontend/src/stores/dashboard.ts +++ b/frontend/src/stores/dashboard.ts @@ -1,4 +1,5 @@ import { defineStore } from "pinia"; +import { useAuthStore } from '@/stores/auth' import { fetchDashboardData, fetchLast7DaysHistory, @@ -7,18 +8,11 @@ import { } from "@/api/dashboard.ts"; export const useDashboardStore = defineStore('dashboard', { - state: () => ({ - token: localStorage.getItem('token') as string | null, - }), - - getters: { - isAuthenticated: (state) => !!state.token, - }, - actions: { async dashboard(): Promise { + const auth = useAuthStore() try { - return await fetchDashboardData(this.token ?? undefined); + return await fetchDashboardData(auth.token ?? undefined); } catch (e) { console.error('Failed to fetch dashboard data', e); throw e; @@ -26,8 +20,9 @@ export const useDashboardStore = defineStore('dashboard', { }, async historyLast7Days(): Promise { + const auth = useAuthStore() try { - return await fetchLast7DaysHistory(this.token ?? undefined); + return await fetchLast7DaysHistory(auth.token ?? undefined) } catch (e) { console.error('Failed to fetch last 7 days history', e); throw e; diff --git a/frontend/src/stores/history.ts b/frontend/src/stores/history.ts index 16f13eb..579b8d3 100644 --- a/frontend/src/stores/history.ts +++ b/frontend/src/stores/history.ts @@ -1,4 +1,5 @@ import {defineStore} from 'pinia'; +import { useAuthStore } from '@/stores/auth' import { fetchHistoryData, type HistoryData, @@ -8,18 +9,11 @@ import { import type {DayStatus} from "@/api/dashboard.ts"; export const useHistoryStore = defineStore('history', { - state: () => ({ - token: localStorage.getItem('token') as string | null, - }), - - getters: { - isAuthenticated: (state) => !!state.token, - }, - actions: { async fetchHistory(): Promise { + const auth = useAuthStore() try { - return await fetchHistoryData(this.token ?? undefined); + return await fetchHistoryData(auth.token ?? undefined); } catch(e) { console.error('Failed to fetch history data', e); throw e; @@ -27,8 +21,9 @@ export const useHistoryStore = defineStore('history', { }, async updateStatus(date: string, status: DayStatus): Promise { + const auth = useAuthStore() try { - return await updateDayStatus(date, status, this.token ?? undefined); + return await updateDayStatus(date, status, auth.token ?? undefined); } catch (e) { console.error(`Failed to update day status for day ${date}`, e); throw e;