mirror of
https://github.com/Spythere/station-manager-2.0.git
synced 2026-05-03 05:28:13 +00:00
fix routingu
This commit is contained in:
+11
-13
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user