This commit is contained in:
@@ -6,11 +6,22 @@ Vue.use(Vuex);
|
|||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
mockAccount: {
|
apiUrl: "http://localhost:7575/api/v8.0/",
|
||||||
username: "manager",
|
userId: 0,
|
||||||
password: "letmein"
|
roles: 0
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
authenticated(state, data) {
|
||||||
|
// mutate state
|
||||||
|
state.authenticated = data.authenticated;
|
||||||
|
state.userId = data.userId;
|
||||||
|
state.roles = data.roles;
|
||||||
|
},
|
||||||
|
notAuthenticated(state) {
|
||||||
|
state.authenticated = false;
|
||||||
|
state.userId = 0;
|
||||||
|
state.roles = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {},
|
|
||||||
actions: {}
|
actions: {}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import decode from "jwt-decode";
|
import decode from "jwt-decode";
|
||||||
import config from "./config";
|
import config from "./config";
|
||||||
import logger from "./logit";
|
import logger from "./logit";
|
||||||
|
import store from "../store";
|
||||||
//import axios from 'axios';
|
//import axios from 'axios';
|
||||||
//import auth0 from 'auth0-js';
|
//import auth0 from 'auth0-js';
|
||||||
//import Router from 'vue-router';
|
//import Router from 'vue-router';
|
||||||
@@ -43,26 +44,9 @@ const AuthorizationRoles = {
|
|||||||
}; //end AuthorizationRoles
|
}; //end AuthorizationRoles
|
||||||
|
|
||||||
const TOKEN_KEY = "apitoken";
|
const TOKEN_KEY = "apitoken";
|
||||||
|
|
||||||
const USER_ROLES = AuthorizationRoles.NoRole;
|
const USER_ROLES = AuthorizationRoles.NoRole;
|
||||||
|
|
||||||
// const CLIENT_ID = '{AUTH0_CLIENT_ID}';
|
|
||||||
// const CLIENT_DOMAIN = '{AUTH0_DOMAIN}';
|
|
||||||
// const REDIRECT = 'YOUR_CALLBACK_URL';
|
|
||||||
// const SCOPE = '{SCOPE}';
|
|
||||||
// const AUDIENCE = 'AUDIENCE_ATTRIBUTE';
|
|
||||||
|
|
||||||
// var auth = new auth0.WebAuth({
|
|
||||||
// clientID: CLIENT_ID,
|
|
||||||
// domain: CLIENT_DOMAIN
|
|
||||||
// });
|
|
||||||
|
|
||||||
export function processLogin(response) {
|
export function processLogin(response) {
|
||||||
//validate token (ensure it's *our* token at least, the server will do the real validation on requests)
|
|
||||||
//response.data.token
|
|
||||||
//store token in central store
|
|
||||||
//todo: put token into localstorage later once this validation is worked out
|
|
||||||
|
|
||||||
//is token present?
|
//is token present?
|
||||||
if (!response || !response.data || !response.data.token) {
|
if (!response || !response.data || !response.data.token) {
|
||||||
logger.log("auth::processLogin -> token empty");
|
logger.log("auth::processLogin -> token empty");
|
||||||
@@ -80,9 +64,15 @@ export function processLogin(response) {
|
|||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
config.apiToken = response.data.token;
|
//Token is valid, store it in session storage
|
||||||
config.userId = Number(token.id);
|
setToken(response.data.token);
|
||||||
config.roles = token["ayanova/roles"];
|
|
||||||
|
//Put app relevant items into vuex store so app can use them
|
||||||
|
store.commit("authenticated", {
|
||||||
|
authenticated: true,
|
||||||
|
userId: Number(token.id),
|
||||||
|
roles: token["ayanova/roles"]
|
||||||
|
});
|
||||||
|
|
||||||
logger.log("User " + token.id + " logged in");
|
logger.log("User " + token.id + " logged in");
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
@@ -94,38 +84,22 @@ export function processLogin(response) {
|
|||||||
|
|
||||||
export function processLogout() {
|
export function processLogout() {
|
||||||
logger.log("Logout");
|
logger.log("Logout");
|
||||||
|
store.commit("notAuthenticated");
|
||||||
clearToken();
|
clearToken();
|
||||||
//router.go('/');
|
//router.go('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// export function requireAuth(to, from, next) {
|
export function getToken() {
|
||||||
// if (!isLoggedIn()) {
|
return sessionStorage.getItem(TOKEN_KEY);
|
||||||
// next({
|
|
||||||
// path: '/',
|
|
||||||
// query: { redirect: to.fullPath }
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// next();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export function getIdToken() {
|
|
||||||
return localStorage.getItem(TOKEN_KEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearToken() {
|
function clearToken() {
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
sessionStorage.removeItem(TOKEN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Helper function that will allow us to extract the access_token and id_token
|
// Get and store token in local storage
|
||||||
// function getParameterByName(name) {
|
|
||||||
// let match = RegExp("[#&]" + name + "=([^&]*)").exec(window.location.hash);
|
|
||||||
// return match && decodeURIComponent(match[1].replace(/\+/g, " "));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Get and store id_token in local storage
|
|
||||||
export function setToken(token) {
|
export function setToken(token) {
|
||||||
localStorage.setItem(TOKEN_KEY, token);
|
sessionStorage.setItem(TOKEN_KEY, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLoggedIn() {
|
export function isLoggedIn() {
|
||||||
|
|||||||
@@ -88,10 +88,13 @@ VUEX STATE PERSISTENCE = VUEX-PERSISTEDSTATE
|
|||||||
- If recreating AyaNova 7 essentially, then that app is always online as well so maybe don't even consider offline work?
|
- If recreating AyaNova 7 essentially, then that app is always online as well so maybe don't even consider offline work?
|
||||||
|
|
||||||
|
|
||||||
LOCALSTORAGE = STORE.JS
|
LOCALSTORAGE = Built in
|
||||||
=-=-=-=-=-=-=-=-=-=-
|
=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
- Very widely used and I don't necessarily need a VUE specific one, this is the one used for pecklist and rockfish
|
- All modern browsers should support it and less libs the better
|
||||||
- https://github.com/marcuswestin/store.js/
|
- Fallback if find it doesn't work:
|
||||||
|
- = STORE.JS Very widely used and I don't necessarily need a VUE specific one, this is the one used for pecklist and rockfish
|
||||||
|
- https://github.com/marcuswestin/store.js/
|
||||||
|
|
||||||
|
|
||||||
SERVICEWORKER = WORKBOX
|
SERVICEWORKER = WORKBOX
|
||||||
=-=-=-=-=-=-=-=-=-=-=-=
|
=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
|
|||||||
Reference in New Issue
Block a user