Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- };
Add Comment
Please, Sign In to add comment