This commit is contained in:
@@ -13,7 +13,17 @@ export default {
|
||||
)
|
||||
.then(apiUtil.status)
|
||||
.then(apiUtil.json)
|
||||
.then(result => {
|
||||
/* eslint-disable-next-line */
|
||||
console.log("auth.js about to process login...");
|
||||
return result;
|
||||
})
|
||||
.then(processLogin)
|
||||
.then(result => {
|
||||
/* eslint-disable-next-line */
|
||||
console.log("auth.js returned from process login, resolving next");
|
||||
return result;
|
||||
})
|
||||
.then(() => {
|
||||
return Promise.resolve(true);
|
||||
}) //succeeded, nothing to return
|
||||
|
||||
@@ -3,17 +3,28 @@ import decode from "jwt-decode";
|
||||
import store from "../store";
|
||||
import initialize from "./initialize";
|
||||
|
||||
// var secondMethod = function(someStuff) {
|
||||
// var promise = new Promise(function(resolve, reject) {
|
||||
// setTimeout(function() {
|
||||
// console.log("second method completed");
|
||||
// resolve({ newData: someStuff.data + " some more data" });
|
||||
// }, 2000);
|
||||
// });
|
||||
// return promise;
|
||||
// };
|
||||
|
||||
export function processLogin(response) {
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
//is token present?
|
||||
if (!response || !response.data || !response.data.token) {
|
||||
store.commit("logItem", "auth::processLogin -> response empty");
|
||||
return Promise.reject();
|
||||
return reject();
|
||||
}
|
||||
const token = decode(response.data.token);
|
||||
|
||||
if (!token || !token.iss) {
|
||||
store.commit("logItem", "auth::processLogin -> response token empty");
|
||||
return Promise.reject();
|
||||
return reject();
|
||||
}
|
||||
|
||||
if (token.iss != "ayanova.com") {
|
||||
@@ -21,7 +32,7 @@ export function processLogin(response) {
|
||||
"logItem",
|
||||
"auth::processLogin -> token invalid (iss): " + token.iss
|
||||
);
|
||||
return Promise.reject();
|
||||
return reject();
|
||||
}
|
||||
|
||||
//Put app relevant items into vuex store so app can use them
|
||||
@@ -33,15 +44,18 @@ export function processLogin(response) {
|
||||
});
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 2 - PROCESS LOGIN - CALILNG INITIALIZE");
|
||||
console.log("STEP 2 - PROCESS LOGIN - CALLING INITIALIZE");
|
||||
|
||||
//Initialize the application
|
||||
initialize();
|
||||
initialize().then(() => {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"auth::processLogin -> User " + token.id + " logged in"
|
||||
);
|
||||
return Promise.resolve(true);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function processLogout() {
|
||||
|
||||
@@ -16,6 +16,7 @@ function addNavItem(title, icon, route) {
|
||||
// Initialize the app
|
||||
// on change of authentication status
|
||||
export default function initialize() {
|
||||
var promise = new Promise(function(resolve) {
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 3 - INITIALIZE TOP");
|
||||
if (store.state.authenticated) {
|
||||
@@ -81,13 +82,11 @@ export default function initialize() {
|
||||
// addNavItem(locale.get("HelpAboutAyaNova"), "info-circle", "/about");
|
||||
// addNavItem(locale.get("Logout"), "sign-out-alt", "/login");
|
||||
})
|
||||
.catch(function handleIntializeError(error) {
|
||||
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
|
||||
throw error;
|
||||
});
|
||||
|
||||
.then(() => {
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 6 - INIT DONE WITH NAV, NOW FETCHING USEROPTIONS SETTINGS");
|
||||
console.log(
|
||||
"STEP 6 - INIT DONE WITH NAV, NOW FETCHING USEROPTIONS SETTINGS"
|
||||
);
|
||||
//CACHE LOCALE SETTINGS
|
||||
api
|
||||
.get("UserOptions/" + store.state.userId)
|
||||
@@ -119,6 +118,7 @@ export default function initialize() {
|
||||
locale.timeZoneOffset = res.data.timeZoneOffset;
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 7 - DONE FETCHING LOCALE SETTINGS");
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch(function handleFetchUserOptionsError(error) {
|
||||
@@ -128,5 +128,12 @@ export default function initialize() {
|
||||
);
|
||||
throw error;
|
||||
});
|
||||
})
|
||||
.catch(function handleIntializeError(error) {
|
||||
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user