Skip to content

Commit 102ad34

Browse files
BatuevIOphysphilefizfakovets
authored
Fix session issues (#281)
## Изменения --------- Co-authored-by: Artem <55246906+physphile@users.noreply.github.com> Co-authored-by: Artem Netsvetaev <physphile@vk.com>
1 parent c10522f commit 102ad34

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/api/controllers/auth/decorators.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,15 @@ export function checkToken<F extends Func<any, any>>(
6565
method: F
6666
): Func<Promise<ReturnType<F>>, Parameters<F>> {
6767
return async (...args: any[]) => {
68-
try {
69-
const { error } = await apiClient.GET('/auth/me');
70-
throw error;
71-
} catch (err) {
72-
const error = err as apiError;
73-
if (error && error.message === 'Forbidden') {
74-
const { deleteToken } = useProfileStore();
75-
const toastStore = useToastStore();
76-
deleteToken();
77-
router.push('/auth');
78-
toastStore.push({ title: 'Сессия истекла' });
79-
}
68+
const { response: checkResponse } = await apiClient.GET('/auth/me');
69+
if (!checkResponse.ok && checkResponse.status === 403) {
70+
const { deleteToken } = useProfileStore();
71+
const toastStore = useToastStore();
72+
deleteToken();
73+
router.push('/auth');
74+
toastStore.push({ title: 'Сессия истекла' });
8075
}
76+
8177
const response = await method(...args);
8278
return response;
8379
};

src/router/auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ export const authHandler: NavigationGuard = async to => {
6969
session_name: navigator.userAgent ?? UNKNOWN_DEVICE,
7070
},
7171
})
72-
: await apiClient.POST(`/auth/${methodLink}/login`, { body: { ...to.query } });
72+
: await apiClient.POST(`/auth/${methodLink}/login`, {
73+
body: {
74+
...to.query,
75+
session_name: navigator.userAgent ?? UNKNOWN_DEVICE,
76+
},
77+
});
7378

7479
if (response.ok && data?.token) {
7580
LocalStorage.set(LocalStorageItem.Token, data.token);

0 commit comments

Comments
 (0)