convenience mode to disable the auth mode for development

This commit is contained in:
Ulf Gebhardt 2021-11-19 21:26:12 +01:00
parent 58a3de8fbb
commit 03e5df5ece
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
4 changed files with 23 additions and 7 deletions

View File

@ -1,2 +1,3 @@
GRAPHQL_URI=http://localhost:4000/graphql
WALLET_AUTH_URL=http://localhost/vue/authenticate?token=$1
DEBUG_DISABLE_AUTH=false

View File

@ -1,15 +1,21 @@
<template>
<div id="app">
<default-layout v-if="$store.state.token" />
<default-layout v-if="showLayout" />
<router-view v-else></router-view>
</div>
</template>
<script>
import defaultLayout from '@/layouts/defaultLayout.vue'
import CONFIG from './config'
export default {
name: 'app',
components: { defaultLayout },
data() {
return {
showLayout: CONFIG.DEBUG_DISABLE_AUTH || this.$store.state.token
}
}
}
</script>

View File

@ -23,6 +23,10 @@ const endpoints = {
WALLET_AUTH_URL: process.env.WALLET_AUTH_URL || 'http://localhost:3000/vue/authenticate?token=$1'
}
const debug = {
DEBUG_DISABLE_AUTH: process.env.DEBUG_DISABLE_AUTH === 'true' || false
}
const options = {}
const CONFIG = {
@ -30,6 +34,7 @@ const CONFIG = {
...environment,
...endpoints,
...options,
...debug,
}
export default CONFIG

View File

@ -1,5 +1,7 @@
import CONFIG from "../config"
const addNavigationGuards = (router, store) => {
// store token on authenticate
// store token on `authenticate`
router.beforeEach((to, from, next) => {
if (to.path === '/authenticate' && to.query.token) {
store.commit('token',to.query.token)
@ -9,11 +11,13 @@ const addNavigationGuards = (router, store) => {
}
})
// protect all routes but not-found
// protect all routes but `not-found`
router.beforeEach((to, from, next) => {
console.log('protect', to.path, from.path)
// handle authentication
if (!store.state.token && to.path !== '/not-found' && to.path !== '/logout') {
if (!CONFIG.DEBUG_DISABLE_AUTH && // we did not disabled the auth module for debug purposes
!store.state.token && // we do not have a token
to.path !== '/not-found' && // we are not on `not-found`
to.path !== '/logout') { // we are not on `logout`
console.log(!CONFIG.DEBUG_DISABLE_AUTH,!store.state.token,to.path !== '/not-found',to.path !== '/logout')
next({ path: '/not-found' })
} else {
next()