Skip to content

Commit d24f457

Browse files
committed
#124 add token cleanup on 403 error
1 parent 8262294 commit d24f457

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

pages/login.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const store = useProfileStore();
1212
const { authLogicUrl } = storeToRefs(useSettingsStore());
1313
1414
if (store.isAuthenticated) {
15+
setPageLayout("default");
1516
await navigateTo("/");
1617
}
1718

src/shared/lib/use-events/use-events-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export const useEventsApi = (): TUseEventsApi => {
8686
// NOTE: clear cached events hardly
8787
eventsStore.removeAll();
8888
}
89-
}).catch((err) => {
90-
console.error('getAll err', err);
89+
}).catch((e) => {
90+
console.error(e);
9191
})
9292
}
9393

src/shared/stores/profile/profile-store.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { defineStore } from "pinia";
2+
import {navigateTo} from "#app"; // eslint-disable-line @conarti/feature-sliced/layers-slices
23
import {REST_API_URL} from "../../lib/io/constants";
34
import type {TProfile} from "../../types";
45
import {getStoredToken, removeStoredToken, setStoredToken} from "./local-storage-actions";
56

67

78
export const useProfileStore = defineStore("profileStore", {
89
state: () => ({
9-
token: '' as string,
10+
token: null as string | null,
1011
profile: undefined as TProfile | undefined,
1112
}),
1213
getters: {
@@ -24,6 +25,18 @@ export const useProfileStore = defineStore("profileStore", {
2425
const profile = await fetch(`${REST_API_URL}/api/me`, {
2526
headers: {"X-Auth-Token": this.token || ""}
2627
})
28+
.then((response) => {
29+
if (!response.ok && response.status === 403) {
30+
this.removeToken();
31+
32+
// TODO: add toast to show error
33+
console.error('Auth Error', response.status, response.statusText)
34+
35+
navigateTo('/login')
36+
}
37+
38+
return response
39+
})
2740
.then((response) => response.json())
2841
.catch((e) => {
2942
console.error(e);
@@ -40,7 +53,10 @@ export const useProfileStore = defineStore("profileStore", {
4053
},
4154
getStoredToken(): string {
4255
const token = getStoredToken()
43-
this.setToken(token);
56+
57+
if (token) {
58+
this.setToken(token);
59+
}
4460

4561
return token
4662
},

src/widgets/ui/page-layout/page-layout.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const props = withDefaults(defineProps<Props>(), {
1919
const { events, cachedEvents } = useEvents();
2020
2121
const isEventsPaused = computed(
22-
() => cachedEvents.idsByType.value[props.type]?.length > 0
22+
() => cachedEvents.idsByType.value[props.type]?.length > 0,
2323
);
2424
2525
const allEvents = computed(() => {
@@ -35,13 +35,13 @@ const visibleEvents = computed(() => {
3535
}
3636
3737
return allEvents.value.filter(({ uuid }) =>
38-
cachedEvents.idsByType.value[props.type]?.includes(uuid)
38+
cachedEvents.idsByType.value[props.type]?.includes(uuid),
3939
);
4040
});
4141
4242
watchEffect(() => {
4343
useTitle(
44-
`${props.title || "Events"}: ${allEvents.value.length} | Buggregator`
44+
`${props.title || "Events"}: ${allEvents.value.length} | Buggregator`,
4545
);
4646
});
4747
</script>
@@ -67,7 +67,7 @@ watchEffect(() => {
6767
@import "src/assets/mixins";
6868
6969
.page-layout {
70-
@apply flex flex-col h-full
70+
@apply flex flex-col h-full w-full;
7171
}
7272
7373
.page-layout__events {

0 commit comments

Comments
 (0)