fix routingu

This commit is contained in:
2023-09-16 18:34:59 +02:00
parent 56246f271a
commit 48efd21178
3 changed files with 18 additions and 14 deletions
+5
View File
@@ -32,6 +32,8 @@ export default defineComponent({
methods: {
async autoLogin() {
try {
this.store.authState = AuthState.LOADING;
const response = await axios.post(
'/auth/token',
{},
@@ -42,9 +44,12 @@ export default defineComponent({
);
this.store.user = response.data;
this.store.authState = AuthState.AUTHORIZED;
this.$router.push('/');
} catch (error) {
this.$router.push('/login');
this.store.authState = AuthState.UNAUTHORIZED;
}
},
},
+2 -1
View File
@@ -14,12 +14,13 @@ export const useStore = defineStore('store', {
stationList: [],
backupList: [],
stationsToRemove: [],
searchedSceneryName: '',
changeList: [],
newStationsCount: 0,
routesModalVisible: true,
currentStation: null,
searchedSceneryName: '',
selectedStationName: '',
user: null,
notifyDiscord: true,
+11 -13
View File
@@ -1,5 +1,5 @@
<template>
<div class="login">
<div class="login" v-if="store.authState != AuthState.LOADING">
<div class="login-header">
<img src="/icon-logo.svg" alt="logo" />
<h1>Stacjownik Station Manager</h1>
@@ -24,12 +24,13 @@
import { defineComponent } from 'vue';
import { useStore, baseURL } from '../store';
import { AuthState } from '../types/types';
import axios, { HttpStatusCode } from 'axios';
import axios from 'axios';
enum LoginState {
INITIALIZED = 0,
LOADING = 1,
LOADED = 2,
ERROR = 3,
}
export default defineComponent({
@@ -53,10 +54,10 @@ export default defineComponent({
methods: {
async signIn(e: Event) {
// this.loginState = LoginState.LOADING;
this.loginState = LoginState.LOADING;
this.store.authState = AuthState.LOADING;
try {
// const loginData = (await this.store.login(this.name, this.password)).data;
const response = await axios.post(
'auth/login',
{ username: this.name, password: this.password },
@@ -66,20 +67,17 @@ export default defineComponent({
}
);
// this.store.authState = AuthState.AUTHORIZED;
// this.loginState = LoginState.LOADED;
// this.store.token = loginData.token;
// this.store.user = loginData.user;
// window.localStorage.setItem('auth-token', this.store.token);
// window.localStorage.setItem('user', JSON.stringify(this.store.user));
this.loginState = LoginState.LOADED;
this.store.authState = AuthState.AUTHORIZED;
this.store.user = response.data;
this.$router.push('/');
this.store.fetchSceneriesData();
} catch (e: any) {
this.loginState = LoginState.ERROR;
this.store.authState = AuthState.UNAUTHORIZED;
if (!e.response || e.response.status === undefined) {
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
return false;