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
+17 -23
View File
@@ -10,8 +10,9 @@ import PopUpCard from './components/PopUpCard.vue';
import { RouterView } from 'vue-router';
import { AuthState } from './types/types';
import useRouteGuard from './mixins/useRouteGuard';
import { useStore } from './store';
import { baseURL, useStore } from './store';
import useLocalStorage from './mixins/useLocalStorage';
import axios from 'axios';
export default defineComponent({
components: { PopUpCard },
@@ -20,7 +21,7 @@ export default defineComponent({
const { routeAuthGuard } = useRouteGuard();
const { setupStorage } = useLocalStorage();
routeAuthGuard();
// routeAuthGuard();
setupStorage();
return {
@@ -30,28 +31,21 @@ export default defineComponent({
methods: {
async autoLogin() {
const token = window.localStorage.getItem('auth-token');
if (!token) {
this.store.authState = AuthState.UNAUTHORIZED;
return;
try {
const response = await axios.post(
'/auth/token',
{},
{
baseURL,
withCredentials: true,
}
);
this.store.user = response.data;
this.$router.push('/');
} catch (error) {
this.$router.push('/login');
}
this.store.token = token;
this.store
.fetchTokenData()
.then((res) => {
this.store.user = res.data.user;
this.store.authState = AuthState.AUTHORIZED;
this.$router.push('/');
})
.catch((err) => {
this.store.isAuthorized = false;
window.localStorage.removeItem('auth-token');
this.store.authState = AuthState.UNAUTHORIZED;
this.$router.push('/login');
});
},
},