This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import logger from "../utils/logit";
|
import logger from "../utils/logit";
|
||||||
import { getToken } from "../utils/authutil";
|
import store from "../store";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
status(response) {
|
status(response) {
|
||||||
@@ -17,7 +17,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
Accept: "application/json, text/plain, */*",
|
Accept: "application/json, text/plain, */*",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + getToken()
|
Authorization: "Bearer " + store.state.apiToken
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default new Vuex.Store({
|
|||||||
state: {
|
state: {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
apiUrl: "http://localhost:7575/api/v8.0/",
|
apiUrl: "http://localhost:7575/api/v8.0/",
|
||||||
|
apiToken: "NOT-AUTHENTICATED",
|
||||||
userId: 0,
|
userId: 0,
|
||||||
roles: 0,
|
roles: 0,
|
||||||
localeText: {},
|
localeText: {},
|
||||||
@@ -20,13 +21,15 @@ export default new Vuex.Store({
|
|||||||
state.authenticated = data.authenticated;
|
state.authenticated = data.authenticated;
|
||||||
state.userId = data.userId;
|
state.userId = data.userId;
|
||||||
state.roles = data.roles;
|
state.roles = data.roles;
|
||||||
|
state.apiToken = data.apiToken;
|
||||||
},
|
},
|
||||||
logout(state) {
|
logout(state) {
|
||||||
|
state.apiToken = "NOT-AUTHENTICATED";
|
||||||
state.authenticated = false;
|
state.authenticated = false;
|
||||||
state.userId = 0;
|
state.userId = 0;
|
||||||
state.roles = 0;
|
state.roles = 0;
|
||||||
state.navItems = [];
|
state.navItems = [];
|
||||||
state.localeText = [];
|
state.localeText = {};
|
||||||
},
|
},
|
||||||
addNavItem(state, data) {
|
addNavItem(state, data) {
|
||||||
state.navItems.push(data);
|
state.navItems.push(data);
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import decode from "jwt-decode";
|
import decode from "jwt-decode";
|
||||||
import config from "./config";
|
|
||||||
import logger from "./logit";
|
import logger from "./logit";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import initialize from "./initialize";
|
import initialize from "./initialize";
|
||||||
|
|
||||||
//import axios from 'axios';
|
|
||||||
//import auth0 from 'auth0-js';
|
|
||||||
//import Router from 'vue-router';
|
|
||||||
//import Auth0Lock from 'auth0-lock';
|
|
||||||
const TOKEN_KEY = "apitoken";
|
|
||||||
|
|
||||||
export function processLogin(response) {
|
export function processLogin(response) {
|
||||||
//is token present?
|
//is token present?
|
||||||
if (!response || !response.data || !response.data.token) {
|
if (!response || !response.data || !response.data.token) {
|
||||||
@@ -28,11 +21,9 @@ export function processLogin(response) {
|
|||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Token is valid, store it in session storage
|
|
||||||
setToken(response.data.token);
|
|
||||||
|
|
||||||
//Put app relevant items into vuex store so app can use them
|
//Put app relevant items into vuex store so app can use them
|
||||||
store.commit("setAuthentication", {
|
store.commit("login", {
|
||||||
|
apiToken: response.data.token,
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
userId: Number(token.id),
|
userId: Number(token.id),
|
||||||
roles: token["ayanova/roles"]
|
roles: token["ayanova/roles"]
|
||||||
@@ -47,27 +38,12 @@ export function processLogin(response) {
|
|||||||
|
|
||||||
export function processLogout() {
|
export function processLogout() {
|
||||||
logger.log("Logout");
|
logger.log("Logout");
|
||||||
store.commit("clearAuthentication");
|
store.commit("logout");
|
||||||
clearToken();
|
|
||||||
//router.go('/');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getToken() {
|
|
||||||
return sessionStorage.getItem(TOKEN_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearToken() {
|
|
||||||
sessionStorage.removeItem(TOKEN_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get and store token in local storage
|
|
||||||
export function setToken(token) {
|
|
||||||
sessionStorage.setItem(TOKEN_KEY, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLoggedIn() {
|
export function isLoggedIn() {
|
||||||
//const token = getToken();
|
//const token = getToken();
|
||||||
return !!config.apiToken && !isTokenExpired(config.apiToken);
|
return !!store.state.apiToken && !isTokenExpired(store.state.apiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTokenExpirationDate(encodedToken) {
|
function getTokenExpirationDate(encodedToken) {
|
||||||
|
|||||||
@@ -31,10 +31,9 @@ WEEK OF 2018-11-12 - RAVEN shell start work. YAY!
|
|||||||
|
|
||||||
|
|
||||||
NEXT UP / CURRENTLY WORKING ON:
|
NEXT UP / CURRENTLY WORKING ON:
|
||||||
|
|
||||||
- lookup naming guidelines for javascript functions (capitalized?) and fixup the code and stick to it.
|
- Look over the (now two) api calls and look for optimization and code shrinkage / de-duplication
|
||||||
- Look over the (now two) api calls and look for optimization and code shrinkage / de-duplication
|
- apiurl handling
|
||||||
- Handle refresh with session storage and how to rehydrate stuff
|
|
||||||
- Move on to the next thing (build and post?)
|
- Move on to the next thing (build and post?)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user