Skip to content

Commit 7c39b9d

Browse files
authored
Merge pull request #68 from Script-languages/FE-01-AuthPage
fix: token przechowywany w wielu miejscach
2 parents 11203cb + 487814d commit 7c39b9d

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

frontend/src/stores/dashboard.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineStore } from "pinia";
2+
import { useAuthStore } from '@/stores/auth'
23
import {
34
fetchDashboardData,
45
fetchLast7DaysHistory,
@@ -7,27 +8,21 @@ import {
78
} from "@/api/dashboard.ts";
89

910
export const useDashboardStore = defineStore('dashboard', {
10-
state: () => ({
11-
token: localStorage.getItem('token') as string | null,
12-
}),
13-
14-
getters: {
15-
isAuthenticated: (state) => !!state.token,
16-
},
17-
1811
actions: {
1912
async dashboard(): Promise<DashboardData> {
13+
const auth = useAuthStore()
2014
try {
21-
return await fetchDashboardData(this.token ?? undefined);
15+
return await fetchDashboardData(auth.token ?? undefined);
2216
} catch (e) {
2317
console.error('Failed to fetch dashboard data', e);
2418
throw e;
2519
}
2620
},
2721

2822
async historyLast7Days(): Promise<Last7DaysResponse> {
23+
const auth = useAuthStore()
2924
try {
30-
return await fetchLast7DaysHistory(this.token ?? undefined);
25+
return await fetchLast7DaysHistory(auth.token ?? undefined)
3126
} catch (e) {
3227
console.error('Failed to fetch last 7 days history', e);
3328
throw e;

frontend/src/stores/history.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {defineStore} from 'pinia';
2+
import { useAuthStore } from '@/stores/auth'
23
import {
34
fetchHistoryData,
45
type HistoryData,
@@ -8,27 +9,21 @@ import {
89
import type {DayStatus} from "@/api/dashboard.ts";
910

1011
export const useHistoryStore = defineStore('history', {
11-
state: () => ({
12-
token: localStorage.getItem('token') as string | null,
13-
}),
14-
15-
getters: {
16-
isAuthenticated: (state) => !!state.token,
17-
},
18-
1912
actions: {
2013
async fetchHistory(): Promise<HistoryData> {
14+
const auth = useAuthStore()
2115
try {
22-
return await fetchHistoryData(this.token ?? undefined);
16+
return await fetchHistoryData(auth.token ?? undefined);
2317
} catch(e) {
2418
console.error('Failed to fetch history data', e);
2519
throw e;
2620
}
2721
},
2822

2923
async updateStatus(date: string, status: DayStatus): Promise<SingleDayEntry> {
24+
const auth = useAuthStore()
3025
try {
31-
return await updateDayStatus(date, status, this.token ?? undefined);
26+
return await updateDayStatus(date, status, auth.token ?? undefined);
3227
} catch (e) {
3328
console.error(`Failed to update day status for day ${date}`, e);
3429
throw e;

0 commit comments

Comments
 (0)