all over the place with comments and console statements but now properly chains all the calls for login (except translation may have an issue)

This commit is contained in:
2020-06-10 21:05:45 +00:00
parent c0fcecb3f8
commit 0a43e53ab7
25 changed files with 1966 additions and 976 deletions

View File

@@ -3,67 +3,101 @@ import decode from "jwt-decode";
import initialize from "./initialize";
export function processLogin(response) {
return new Promise(function(resolve, reject) {
//check there is a response of some kind
if (!response) {
window.$gz.store.commit("logItem", "auth::processLogin -> no response");
return reject();
}
return new Promise(async function(resolve, reject) {
try {
console.log("authutil:process login TOP");
//is there an error?
if (response.error) {
return reject(response.error);
}
//check there is a response of some kind
if (!response) {
window.$gz.store.commit("logItem", "auth::processLogin -> no response");
return reject();
}
//is token present?
if (!response.data || !response.data.token) {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response contains no data"
);
return reject();
}
const token = decode(response.data.token);
//is there an error?
if (response.error) {
return reject(response.error);
}
if (!token || !token.iss) {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response token empty"
);
return reject();
}
//is token present?
if (!response.data || !response.data.token) {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response contains no data"
);
return reject();
}
const token = decode(response.data.token);
if (token.iss != "ayanova.com") {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> token invalid (iss): " + token.iss
);
return reject();
}
if (!token || !token.iss) {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response token empty"
);
return reject();
}
//ensure the store is clean first in case we didn't come here from a clean logout
window.$gz.store.commit("logout");
sessionStorage.clear(); //clear all temporary session storage data
if (token.iss != "ayanova.com") {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> token invalid (iss): " + token.iss
);
return reject();
}
//Put app relevant items into vuex store so app can use them
window.$gz.store.commit("login", {
apiToken: response.data.token,
authenticated: true,
userId: Number(token.id),
userName: response.data.name,
roles: response.data.roles,
userType: response.data.usertype,
dlt: response.data.dlt
});
//ensure the store is clean first in case we didn't come here from a clean logout
window.$gz.store.commit("logout");
sessionStorage.clear(); //clear all temporary session storage data
//Initialize the application
initialize().then(() => {
//Put app relevant items into vuex store so app can use them
window.$gz.store.commit("login", {
apiToken: response.data.token,
authenticated: true,
userId: Number(token.id),
userName: response.data.name,
roles: response.data.roles,
userType: response.data.usertype,
dlt: response.data.dlt
});
//log the login
window.$gz.store.commit(
"logItem",
"auth::processLogin -> User " + token.id + " logged in"
);
resolve(true);
});
//Get global settings
console.log("authutil:calling get blobal settings");
let gsets = await window.$gz.api.get("global-biz-setting/client");
console.log("authutil:got global settings");
if (gsets.error) {
//In a form this would trigger a bunch of validation or error display code but for here and now:
//convert error to human readable string for display and popup a notification to user
let msg = window.$gz.api.apiErrorToHumanString(gsets.error);
window.$gz.store.commit(
"logItem",
"Initialize::() fetch global-biz-setting/client -> error" + msg
);
window.$gz.eventBus.$emit("notify-error", msg);
} else {
//Check if overrides and use them here
//or else use browser defaults
window.$gz.store.commit("setGlobalSettings", gsets.data);
}
console.log("** authutil calling test delay --->>>>");
await window.$gz.api.doDelayAsync();
console.log("** authutil back from delay continuing..");
//INITIALIZE
console.log("authutil:calling initialize");
await initialize();
} catch (err) {
console.log("authutil:error in async chain global/init");
reject(err);
}
console.log("authutil:no error resolving async chain global/init");
resolve();
//-------------------------------------------------
});
}