Added user data loader
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f7b5dc41ca
commit
02af4b667e
31
src/App.vue
31
src/App.vue
@ -1,12 +1,39 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<router-view/>
|
||||
|
||||
<md-snackbar md-position="center" :md-duration="4000" :md-active.sync="showWelcome">
|
||||
<span>Welcome back {{ $store.state.auth.name }}!</span>
|
||||
</md-snackbar>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
<script>
|
||||
|
||||
</style>
|
||||
import {mapState} from 'vuex';
|
||||
|
||||
export default {
|
||||
name: "App",
|
||||
data() {
|
||||
return {
|
||||
showWelcome: false
|
||||
}
|
||||
},
|
||||
computed: mapState('auth', ['name']),
|
||||
mounted() {
|
||||
this.$store.dispatch("auth/loadUserData").catch(() => {
|
||||
this.$router.push({name: "Welcome"});
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
name(newValue, oldValue) {
|
||||
if (oldValue === '') {
|
||||
this.showWelcome = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#app {
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
MdRipple,
|
||||
MdDialog,
|
||||
MdSpeedDial,
|
||||
MdDivider,
|
||||
MdSnackbar,
|
||||
MdSubheader
|
||||
} from 'vue-material/dist/components'
|
||||
|
||||
@ -42,7 +42,7 @@ Vue.use(MdAvatar);
|
||||
Vue.use(MdRipple);
|
||||
Vue.use(MdDialog);
|
||||
Vue.use(MdSpeedDial);
|
||||
Vue.use(MdDivider);
|
||||
Vue.use(MdSnackbar);
|
||||
Vue.use(MdSubheader);
|
||||
|
||||
Vue.prototype.$api = axios.create({
|
||||
|
@ -31,6 +31,7 @@ export default {
|
||||
state.name = '';
|
||||
},
|
||||
logout(state) {
|
||||
state.processing = false;
|
||||
state.token = '';
|
||||
state.name = '';
|
||||
}
|
||||
@ -38,7 +39,7 @@ export default {
|
||||
actions: {
|
||||
performLogin({commit}, creds) {
|
||||
return new Promise((resolve, reject) => {
|
||||
commit('auth_started')
|
||||
commit('auth_started');
|
||||
axios.post("auth/login", creds, {baseURL}).then(resp => {
|
||||
const token = resp.data.token;
|
||||
|
||||
@ -46,12 +47,12 @@ export default {
|
||||
return reject();
|
||||
}
|
||||
|
||||
localStorage.setItem(JWT_KEY_NAME, token)
|
||||
commit('auth_success', {token, name: creds.name})
|
||||
localStorage.setItem(JWT_KEY_NAME, token);
|
||||
commit('auth_success', {token, name: creds.name});
|
||||
return resolve(resp);
|
||||
}).catch(err => {
|
||||
commit('auth_fail')
|
||||
localStorage.removeItem(JWT_KEY_NAME)
|
||||
commit('auth_fail');
|
||||
localStorage.removeItem(JWT_KEY_NAME);
|
||||
return reject(err);
|
||||
})
|
||||
})
|
||||
@ -66,13 +67,12 @@ export default {
|
||||
return reject();
|
||||
}
|
||||
|
||||
|
||||
localStorage.setItem(JWT_KEY_NAME, token)
|
||||
commit('auth_success', {token, name: creds.name})
|
||||
localStorage.setItem(JWT_KEY_NAME, token);
|
||||
commit('auth_success', {token, name: creds.name});
|
||||
resolve(resp)
|
||||
}).catch(err => {
|
||||
commit('auth_fail')
|
||||
localStorage.removeItem(JWT_KEY_NAME)
|
||||
commit('auth_fail');
|
||||
localStorage.removeItem(JWT_KEY_NAME);
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
@ -83,6 +83,27 @@ export default {
|
||||
commit('logout')
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
loadUserData({commit, state}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (state.token && !state.name) {
|
||||
commit('auth_started');
|
||||
axios.get('auth/me', {
|
||||
baseURL,
|
||||
headers: {"Authorization": "Bearer " + state.token}
|
||||
}).then((data) => {
|
||||
commit("auth_success", {
|
||||
token: state.token,
|
||||
name: data.data.name
|
||||
});
|
||||
return resolve();
|
||||
}).catch(() => {
|
||||
commit("auth_fail");
|
||||
localStorage.removeItem(JWT_KEY_NAME);
|
||||
return reject();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
modules: {},
|
||||
|
@ -137,13 +137,12 @@ export default {
|
||||
},
|
||||
// --- end of magic hack
|
||||
handleNodeMove(id) {
|
||||
console.log(id);
|
||||
const moved_node = this.model.nodes.find((node) => node.id === id);
|
||||
console.log(moved_node);
|
||||
|
||||
if ((!moved_node) || (!moved_node.apiId)) {
|
||||
return;
|
||||
}
|
||||
console.log("Anyád")
|
||||
|
||||
this.pendingNodeMoves++;
|
||||
this.$api.put(`objects/streamerobjects/coordmodify/${moved_node.apiId}`, {
|
||||
x: moved_node.x,
|
||||
|
Loading…
Reference in New Issue
Block a user