2023-08-04 13:34:18 +02:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
import { notify } from "@kyvg/vue3-notification";
|
|
|
|
import { apiWrapper } from '@/helpers/fetch-wrapper'
|
|
|
|
|
2025-03-04 22:23:37 +01:00
|
|
|
export const securityStore = defineStore('security',{
|
2023-08-04 13:34:18 +02:00
|
|
|
state: () => ({
|
|
|
|
csrfToken: "",
|
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
CsrfToken: (state) => state.csrfToken,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
SetCsrfToken(token) {
|
|
|
|
this.csrfToken = token
|
|
|
|
},
|
|
|
|
// LoadSecurityProperties always returns a fulfilled promise, even if the request failed.
|
|
|
|
async LoadSecurityProperties() {
|
|
|
|
await apiWrapper.get(`/csrf`)
|
|
|
|
.then(token => this.SetCsrfToken(token))
|
|
|
|
.catch(error => {
|
|
|
|
this.SetCsrfToken("");
|
|
|
|
console.log("Failed to load csrf token: ", error);
|
|
|
|
notify({
|
|
|
|
title: "Backend Connection Failure",
|
|
|
|
text: "Failed to load csrf token!",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2025-03-04 22:23:37 +01:00
|
|
|
});
|