Last active
January 27, 2018 23:55
-
-
Save robneville73/324c5ff86fd5ac3281f10f2477f14e54 to your computer and use it in GitHub Desktop.
global guard not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
import router from "../../router"; | |
const state = { | |
authenticated: false, | |
auth: {}, | |
loggedin_siteid: null, | |
login_inprogress: false | |
}; | |
const getters = { | |
authenticated: state => { | |
return state.authenticated; | |
} | |
}; | |
const mutations = { | |
initializeAuth(state, auth_obj) { | |
state.auth = auth_obj; | |
state.authenticated = true; | |
router.push({ name: "main" }); | |
}, | |
updateLoggedInSite(state, siteid) { | |
state.siteid = siteid; | |
}, | |
loginStart(state) { | |
state.login_inprogress = true; | |
}, | |
loginFinish(state) { | |
state.login_inprogress = false; | |
} | |
}; | |
const actions = { | |
authenticate({ commit }, login_obj) { | |
commit("loginStart"); | |
axios | |
.get("/authenticate", { | |
params: { | |
username: login_obj.username, | |
password: login_obj.password, | |
siteid: login_obj.siteid, | |
flex: "true" | |
} | |
}) | |
.then(({ data: { response: response } }) => { | |
commit("loginFinish"); | |
const errors = response.errors; | |
if (errors) { | |
console.log(errors); | |
} else { | |
commit("initializeAuth", response.results[0]); | |
commit("updateLoggedInSite", login_obj.siteid); | |
} | |
}); | |
} | |
}; | |
export default { | |
state, | |
mutations, | |
actions, | |
getters | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Vue build version to load with the `import` command | |
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. | |
import Vue from "vue"; | |
import Vuetify from "vuetify"; | |
import axios from "axios"; | |
import App from "./App"; | |
import store from "./store/store"; | |
import router from "./router"; | |
import("vuetify/dist/vuetify.min.css"); // Ensure you are using css-loader | |
axios.defaults.baseURL = "https://jayne.retailarchitects.com/tg/"; | |
Vue.config.productionTip = false; | |
Vue.use(Vuetify); | |
/* eslint-disable no-new */ | |
new Vue({ | |
el: "#app", | |
router, | |
store, | |
components: { App }, | |
template: "<App/>" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from "vue"; | |
import Router from "vue-router"; | |
import store from "../store/store"; | |
import Login from "@/components/Login"; | |
import Main from "@/components/Main"; | |
import Location from "@/components/Location"; | |
Vue.use(Router); | |
const router = new Router({ | |
routes: [ | |
{ | |
path: "/", | |
name: "main", | |
component: Main | |
}, | |
{ | |
path: "/login", | |
name: "login", | |
component: Login | |
}, | |
{ | |
path: "/location/:locationid", | |
name: "location", | |
component: Location | |
} | |
] | |
}); | |
router.beforeEach((to, from, next) => { | |
if (to.name !== "login" && !store.getters.authenticated) { | |
next({ name: "login" }); | |
} else { | |
next(); | |
} | |
}); | |
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from "vue"; | |
import Vuex from "vuex"; | |
import authenticate from "./modules/authenticate"; | |
Vue.use(Vuex); | |
const store = new Vuex.Store({ | |
modules: [authenticate] | |
}); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
also tried moving the guard clause after the root Vue object is instantiated just for giggles...no good.