mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 21:48:14 +00:00
fix routingu
This commit is contained in:
@@ -32,6 +32,8 @@ export default defineComponent({
|
|||||||
methods: {
|
methods: {
|
||||||
async autoLogin() {
|
async autoLogin() {
|
||||||
try {
|
try {
|
||||||
|
this.store.authState = AuthState.LOADING;
|
||||||
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'/auth/token',
|
'/auth/token',
|
||||||
{},
|
{},
|
||||||
@@ -42,9 +44,12 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.store.user = response.data;
|
this.store.user = response.data;
|
||||||
|
this.store.authState = AuthState.AUTHORIZED;
|
||||||
|
|
||||||
this.$router.push('/');
|
this.$router.push('/');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$router.push('/login');
|
this.$router.push('/login');
|
||||||
|
this.store.authState = AuthState.UNAUTHORIZED;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-1
@@ -14,12 +14,13 @@ export const useStore = defineStore('store', {
|
|||||||
stationList: [],
|
stationList: [],
|
||||||
backupList: [],
|
backupList: [],
|
||||||
stationsToRemove: [],
|
stationsToRemove: [],
|
||||||
searchedSceneryName: '',
|
|
||||||
changeList: [],
|
changeList: [],
|
||||||
newStationsCount: 0,
|
newStationsCount: 0,
|
||||||
routesModalVisible: true,
|
routesModalVisible: true,
|
||||||
currentStation: null,
|
currentStation: null,
|
||||||
|
searchedSceneryName: '',
|
||||||
selectedStationName: '',
|
selectedStationName: '',
|
||||||
|
|
||||||
user: null,
|
user: null,
|
||||||
notifyDiscord: true,
|
notifyDiscord: true,
|
||||||
|
|
||||||
|
|||||||
+11
-13
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="login">
|
<div class="login" v-if="store.authState != AuthState.LOADING">
|
||||||
<div class="login-header">
|
<div class="login-header">
|
||||||
<img src="/icon-logo.svg" alt="logo" />
|
<img src="/icon-logo.svg" alt="logo" />
|
||||||
<h1>Stacjownik Station Manager</h1>
|
<h1>Stacjownik Station Manager</h1>
|
||||||
@@ -24,12 +24,13 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { useStore, baseURL } from '../store';
|
import { useStore, baseURL } from '../store';
|
||||||
import { AuthState } from '../types/types';
|
import { AuthState } from '../types/types';
|
||||||
import axios, { HttpStatusCode } from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
enum LoginState {
|
enum LoginState {
|
||||||
INITIALIZED = 0,
|
INITIALIZED = 0,
|
||||||
LOADING = 1,
|
LOADING = 1,
|
||||||
LOADED = 2,
|
LOADED = 2,
|
||||||
|
ERROR = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -53,10 +54,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
async signIn(e: Event) {
|
async signIn(e: Event) {
|
||||||
// this.loginState = LoginState.LOADING;
|
this.loginState = LoginState.LOADING;
|
||||||
|
this.store.authState = AuthState.LOADING;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// const loginData = (await this.store.login(this.name, this.password)).data;
|
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'auth/login',
|
'auth/login',
|
||||||
{ username: this.name, password: this.password },
|
{ username: this.name, password: this.password },
|
||||||
@@ -66,20 +67,17 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// this.store.authState = AuthState.AUTHORIZED;
|
this.loginState = LoginState.LOADED;
|
||||||
// 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.store.authState = AuthState.AUTHORIZED;
|
||||||
this.store.user = response.data;
|
this.store.user = response.data;
|
||||||
this.$router.push('/');
|
this.$router.push('/');
|
||||||
|
|
||||||
this.store.fetchSceneriesData();
|
this.store.fetchSceneriesData();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
this.loginState = LoginState.ERROR;
|
||||||
|
this.store.authState = AuthState.UNAUTHORIZED;
|
||||||
|
|
||||||
if (!e.response || e.response.status === undefined) {
|
if (!e.response || e.response.status === undefined) {
|
||||||
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
this.errorMessage = 'Wystąpił błąd podczas łączenia z serwerem!';
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user