axios: baseURL

This commit is contained in:
2023-02-10 14:42:11 +01:00
parent 446698b832
commit 580e109dda
7 changed files with 86 additions and 98 deletions
+4 -19
View File
@@ -23,7 +23,6 @@
<script lang="ts">
import axios from 'axios';
import { defineComponent } from 'vue';
import dataMixin from '../mixins/dataMixin';
import { useStore } from '../store';
import { AuthState, ILoginResponse } from '../types/types';
@@ -34,8 +33,6 @@ enum LoginState {
}
export default defineComponent({
mixins: [dataMixin],
data() {
return {
errorMessage: '',
@@ -61,31 +58,19 @@ export default defineComponent({
console.log('Ładowanie');
try {
const data: ILoginResponse = (
await axios.post(
`${this.API_URL}/auth/login`,
{ username: this.name, password: this.password },
{
headers: {
'Content-Type': 'application/json',
},
}
)
).data;
const loginData = (await this.store.login(this.name, this.password)).data;
this.store.authState = AuthState.AUTHORIZED;
this.loginState = LoginState.LOADED;
this.store.token = data.token;
this.store.user = data.user;
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));
console.log('Gituwa');
this.$router.push('/');
this.loadData();
this.store.fetchSceneriesData();
} catch (e: any) {
this.store.authState = AuthState.UNAUTHORIZED;
this.loginState = LoginState.LOADED;
+2 -3
View File
@@ -58,7 +58,6 @@
<script lang="ts">
import { defineComponent } from 'vue';
import changeMixin from '../mixins/changeMixin';
import dataMixin from '../mixins/dataMixin';
import { useStore } from '../store';
import { SceneryRowItem, Availability, AuthState } from '../types/types';
import RoutesModal from '../components/RoutesModal.vue';
@@ -68,7 +67,7 @@ import UpdateCard from '../components/UpdateCard.vue';
export default defineComponent({
components: { RoutesModal, TableActions, UpdateCard },
mixins: [dataMixin, changeMixin, routesMixin],
mixins: [changeMixin, routesMixin],
data: () => ({
AuthState,
@@ -97,7 +96,7 @@ export default defineComponent({
},
mounted() {
this.loadData();
this.store.fetchSceneriesData();
},
computed: {