Skip to content
Snippets Groups Projects
Commit c1d2a699 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Fix: Handle 401 Unauthorized error and force logout in user store

parent ba6d5eff
No related branches found
No related tags found
No related merge requests found
Pipeline #1512357 passed with warnings
...@@ -24,6 +24,8 @@ import type { ...@@ -24,6 +24,8 @@ import type {
UserMergeDto, UserMergeDto,
} from "@coscine/api-client/dist/types/Coscine.Api"; } from "@coscine/api-client/dist/types/Coscine.Api";
import { wrapListRequest } from "@/util/wrapListRequest"; import { wrapListRequest } from "@/util/wrapListRequest";
import axios from "axios";
import useLoginStore from "../login/store";
/* /*
Store variable name is "this.<id>Store" Store variable name is "this.<id>Store"
...@@ -230,10 +232,17 @@ export const useUserStore = defineStore({ ...@@ -230,10 +232,17 @@ export const useUserStore = defineStore({
const apiResponse = await SelfApi.getCurrentUser(); const apiResponse = await SelfApi.getCurrentUser();
this.user = apiResponse.data.data; this.user = apiResponse.data.data;
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) {
if (error.response?.status === 401) {
// If 401 Unauthorized is returned, force a logout
const loginStore = useLoginStore();
loginStore.logout();
}
// Handle other Status Codes // Handle other Status Codes
notificationStore.postApiErrorNotification(error as AxiosError); notificationStore.postApiErrorNotification(error as AxiosError);
} }
this.isRetrievingUser = false; this.isRetrievingUser = false;
}
}, },
async deleteToken(tokenId: string) { async deleteToken(tokenId: string) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment