This commit is contained in:
2019-04-29 23:00:55 +00:00
parent aa3751be35
commit 6ffbbc11de
3 changed files with 176 additions and 145 deletions

View File

@@ -13,7 +13,17 @@ export default {
) )
.then(apiUtil.status) .then(apiUtil.status)
.then(apiUtil.json) .then(apiUtil.json)
.then(result => {
/* eslint-disable-next-line */
console.log("auth.js about to process login...");
return result;
})
.then(processLogin) .then(processLogin)
.then(result => {
/* eslint-disable-next-line */
console.log("auth.js returned from process login, resolving next");
return result;
})
.then(() => { .then(() => {
return Promise.resolve(true); return Promise.resolve(true);
}) //succeeded, nothing to return }) //succeeded, nothing to return

View File

@@ -3,17 +3,28 @@ import decode from "jwt-decode";
import store from "../store"; import store from "../store";
import initialize from "./initialize"; 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) { export function processLogin(response) {
var promise = new Promise(function(resolve, reject) {
//is token present? //is token present?
if (!response || !response.data || !response.data.token) { if (!response || !response.data || !response.data.token) {
store.commit("logItem", "auth::processLogin -> response empty"); store.commit("logItem", "auth::processLogin -> response empty");
return Promise.reject(); return reject();
} }
const token = decode(response.data.token); const token = decode(response.data.token);
if (!token || !token.iss) { if (!token || !token.iss) {
store.commit("logItem", "auth::processLogin -> response token empty"); store.commit("logItem", "auth::processLogin -> response token empty");
return Promise.reject(); return reject();
} }
if (token.iss != "ayanova.com") { if (token.iss != "ayanova.com") {
@@ -21,7 +32,7 @@ export function processLogin(response) {
"logItem", "logItem",
"auth::processLogin -> token invalid (iss): " + token.iss "auth::processLogin -> token invalid (iss): " + token.iss
); );
return Promise.reject(); return reject();
} }
//Put app relevant items into vuex store so app can use them //Put app relevant items into vuex store so app can use them
@@ -33,15 +44,18 @@ export function processLogin(response) {
}); });
/* eslint-disable-next-line */ /* eslint-disable-next-line */
console.log("STEP 2 - PROCESS LOGIN - CALILNG INITIALIZE"); console.log("STEP 2 - PROCESS LOGIN - CALLING INITIALIZE");
//Initialize the application //Initialize the application
initialize(); initialize().then(() => {
store.commit( store.commit(
"logItem", "logItem",
"auth::processLogin -> User " + token.id + " logged in" "auth::processLogin -> User " + token.id + " logged in"
); );
return Promise.resolve(true); resolve(true);
});
});
return promise;
} }
export function processLogout() { export function processLogout() {

View File

@@ -16,6 +16,7 @@ function addNavItem(title, icon, route) {
// Initialize the app // Initialize the app
// on change of authentication status // on change of authentication status
export default function initialize() { export default function initialize() {
var promise = new Promise(function(resolve) {
/* eslint-disable-next-line */ /* eslint-disable-next-line */
console.log("STEP 3 - INITIALIZE TOP"); console.log("STEP 3 - INITIALIZE TOP");
if (store.state.authenticated) { if (store.state.authenticated) {
@@ -81,13 +82,11 @@ export default function initialize() {
// addNavItem(locale.get("HelpAboutAyaNova"), "info-circle", "/about"); // addNavItem(locale.get("HelpAboutAyaNova"), "info-circle", "/about");
// addNavItem(locale.get("Logout"), "sign-out-alt", "/login"); // addNavItem(locale.get("Logout"), "sign-out-alt", "/login");
}) })
.catch(function handleIntializeError(error) { .then(() => {
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
throw error;
});
/* eslint-disable-next-line */ /* 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 //CACHE LOCALE SETTINGS
api api
.get("UserOptions/" + store.state.userId) .get("UserOptions/" + store.state.userId)
@@ -119,6 +118,7 @@ export default function initialize() {
locale.timeZoneOffset = res.data.timeZoneOffset; locale.timeZoneOffset = res.data.timeZoneOffset;
/* eslint-disable-next-line */ /* eslint-disable-next-line */
console.log("STEP 7 - DONE FETCHING LOCALE SETTINGS"); console.log("STEP 7 - DONE FETCHING LOCALE SETTINGS");
resolve();
} }
}) })
.catch(function handleFetchUserOptionsError(error) { .catch(function handleFetchUserOptionsError(error) {
@@ -128,5 +128,12 @@ export default function initialize() {
); );
throw error; throw error;
}); });
})
.catch(function handleIntializeError(error) {
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
throw error;
});
} }
});
return promise;
} }