mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 21:48:14 +00:00
poprawki bezpieczeństwa
This commit is contained in:
+17
-23
@@ -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');
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user