poprawki bezpieczeństwa

This commit is contained in:
2023-09-16 17:11:13 +02:00
parent 00307fadad
commit 56246f271a
17 changed files with 396 additions and 402 deletions
+7 -33
View File
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
import { AuthState, ILoginResponse, IStore, IUser, SceneryRowItem } from './types/types';
import axios from 'axios';
const baseURL = import.meta.env[`VITE_API_URL${import.meta.env.DEV ? '_DEV' : ''}`];
export const baseURL = import.meta.env[`VITE_API_URL${import.meta.env.DEV ? '_DEV' : ''}`];
export const useStore = defineStore('store', {
state: () =>
@@ -20,9 +20,7 @@ export const useStore = defineStore('store', {
routesModalVisible: true,
currentStation: null,
selectedStationName: '',
token: null,
user: null,
isAuthorized: false,
notifyDiscord: true,
alertMessage: '',
@@ -37,12 +35,8 @@ export const useStore = defineStore('store', {
fetchSceneriesData() {
this.dataState = 'LOADING';
const data = axios.get<SceneryRowItem[]>(`api/getSceneries?time=${Date.now()}`, {
const data = axios.get<SceneryRowItem[]>(`api/getSceneries`, {
baseURL,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.token}`,
},
});
data
@@ -55,13 +49,13 @@ export const useStore = defineStore('store', {
})
.catch(() => {
this.dataState = 'ERROR';
this.token = '';
this.isAuthorized = false;
});
},
updateSceneriesData(mappedChangeList: any[]) {
const response = axios.post(
async updateSceneriesData(mappedChangeList: any[]) {
console.log(mappedChangeList);
const response = await axios.post(
'/manager/updateSceneryList',
{
changeList: mappedChangeList,
@@ -69,32 +63,12 @@ export const useStore = defineStore('store', {
},
{
baseURL,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.token}`,
},
withCredentials: true,
}
);
return response;
},
login(name: string, pwd: string) {
return axios.post<ILoginResponse>(
'auth/login',
{ username: name, password: pwd },
{
baseURL,
headers: {
'Content-Type': 'application/json',
},
}
);
},
fetchTokenData() {
return axios.post<{ user: IUser }>('auth/token', { token: this.token }, { baseURL });
},
},
getters: {