stash
This commit is contained in:
parent
06f7c515ef
commit
b98c368540
4 changed files with 20 additions and 13 deletions
|
@ -15,10 +15,10 @@ import store from '@/store';
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App',
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(['init'])
|
...mapMutations(['init']),
|
||||||
},
|
},
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
store.commit('init')
|
store.commit('load_local')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -11,9 +11,9 @@ import store from './store';
|
||||||
|
|
||||||
import _nacl from 'js-nacl';
|
import _nacl from 'js-nacl';
|
||||||
|
|
||||||
const app = createApp(App).use(router).use(store).use(BootstrapIconsPlugin);
|
const app = createApp(App).use(store).use(BootstrapIconsPlugin);
|
||||||
|
|
||||||
_nacl.instantiate((nacl) => {
|
_nacl.instantiate((nacl) => {
|
||||||
window.nacl = nacl
|
window.nacl = nacl
|
||||||
app.mount('#app')
|
app.use(router).mount('#app')
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,6 +40,7 @@ router.beforeEach((to, from) => {
|
||||||
if (to.meta.requiresAuth && !store.getters.isLoggedIn) {
|
if (to.meta.requiresAuth && !store.getters.isLoggedIn) {
|
||||||
// this route requires auth, check if logged in
|
// this route requires auth, check if logged in
|
||||||
// if not, redirect to login page.
|
// if not, redirect to login page.
|
||||||
|
console.log("Not logged in, redirecting to login page")
|
||||||
return {
|
return {
|
||||||
path: '/login',
|
path: '/login',
|
||||||
// save the location we were at to come back later
|
// save the location we were at to come back later
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {createSignAuth, createTokenAuth, ServerSet} from "@/federation";
|
||||||
|
|
||||||
export default createStore({
|
export default createStore({
|
||||||
state: {
|
state: {
|
||||||
|
local_loaded: false,
|
||||||
user: null,
|
user: null,
|
||||||
token: null,
|
token: null,
|
||||||
keypair: null,
|
keypair: null,
|
||||||
|
@ -69,7 +70,9 @@ export default createStore({
|
||||||
localStorage.removeItem('keypair');
|
localStorage.removeItem('keypair');
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
},
|
},
|
||||||
init(state) {
|
load_local(state) {
|
||||||
|
if (state.local_loaded)
|
||||||
|
return;
|
||||||
const remember = localStorage.getItem('remember');
|
const remember = localStorage.getItem('remember');
|
||||||
const user = localStorage.getItem('user');
|
const user = localStorage.getItem('user');
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
|
@ -79,16 +82,9 @@ export default createStore({
|
||||||
this.commit('setToken', token);
|
this.commit('setToken', token);
|
||||||
if (keypair) {
|
if (keypair) {
|
||||||
this.commit('setKey', keypair)
|
this.commit('setKey', keypair)
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
router.push('/');
|
|
||||||
|
|
||||||
/*if (this.$route.query.redirect) {
|
|
||||||
router.push({path: this.$route.query.redirect});
|
|
||||||
} else {
|
|
||||||
router.push({path: '/'});
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
state.cache_loaded = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -300,6 +296,16 @@ export default createStore({
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
isLoggedIn(state) {
|
isLoggedIn(state) {
|
||||||
|
if (!state.local_loaded) {
|
||||||
|
state.remember = localStorage.getItem('remember') === 'true'
|
||||||
|
state.user = localStorage.getItem('user')
|
||||||
|
state.token = localStorage.getItem('token')
|
||||||
|
const keypair = localStorage.getItem('keypair')
|
||||||
|
if (keypair)
|
||||||
|
state.keypair = nacl.crypto_sign_keypair_from_seed(nacl.from_hex(keypair))
|
||||||
|
state.local_loaded = true
|
||||||
|
}
|
||||||
|
|
||||||
return state.user !== null && state.token !== null;
|
return state.user !== null && state.token !== null;
|
||||||
},
|
},
|
||||||
signAuth(state) {
|
signAuth(state) {
|
||||||
|
|
Loading…
Reference in a new issue