Fix login not updating header bar

This commit is contained in:
Matthias 2020-07-19 15:12:06 +02:00
parent 5a7184efa8
commit 9a6e4b4306
4 changed files with 15 additions and 5 deletions

View File

@ -38,6 +38,7 @@
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import Login from '@/views/Login.vue';
import { State, Mutation } from 'vuex-class';
import userService from '../../shared/userService';
import BootswatchThemeSelect from '../BootswatchThemeSelect.vue';
@ -45,13 +46,13 @@ import BootswatchThemeSelect from '../BootswatchThemeSelect.vue';
components: { Login, BootswatchThemeSelect },
})
export default class NavBar extends Vue {
get loggedIn(): boolean {
console.log(userService.loggedIn());
return userService.loggedIn();
}
@State loggedIn;
@Mutation setLoggedIn;
logout(): void {
userService.logout();
this.setLoggedIn(false);
}
}
</script>

View File

@ -3,7 +3,7 @@ import userService from './userService';
export const api = axios.create({
baseURL: userService.apiBase,
timeout: 2000,
timeout: 5000,
withCredentials: true,
});

View File

@ -3,12 +3,14 @@ import Vuex from 'vuex';
import ftbotModule from './modules/ftbot';
import alertsModule from './modules/alerts';
import userService from '../shared/userService';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
ping: '',
loggedIn: userService.loggedIn(),
},
modules: {
ftbot: ftbotModule,
@ -20,6 +22,9 @@ export default new Vuex.Store({
const now = Date.now();
state.ping = `${ping.status} ${now.toString()}`;
},
setLoggedIn(state, loggedin: boolean) {
state.loggedIn = loggedin;
},
},
actions: {
refreshOnce({ dispatch }) {

View File

@ -63,6 +63,7 @@
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Mutation } from 'vuex-class';
import userService from '../shared/userService';
import { setBaseUrl } from '../shared/apiService';
@ -70,6 +71,8 @@ import { AuthPayload } from '../store/types';
@Component({})
export default class Login extends Vue {
@Mutation setLoggedIn;
$refs!: {
form: HTMLFormElement;
};
@ -116,6 +119,7 @@ export default class Login extends Vue {
.login(this.auth)
.then(() => {
console.log('Login success.');
this.setLoggedIn(true);
this.$nextTick(() => {
this.$bvModal.hide('modal-prevent-closing');
});