This commit is contained in:
@@ -3,45 +3,59 @@ 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) {
|
||||
//is token present?
|
||||
if (!response || !response.data || !response.data.token) {
|
||||
store.commit("logItem", "auth::processLogin -> response empty");
|
||||
return Promise.reject();
|
||||
}
|
||||
const token = decode(response.data.token);
|
||||
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 reject();
|
||||
}
|
||||
const token = decode(response.data.token);
|
||||
|
||||
if (!token || !token.iss) {
|
||||
store.commit("logItem", "auth::processLogin -> response token empty");
|
||||
return Promise.reject();
|
||||
}
|
||||
if (!token || !token.iss) {
|
||||
store.commit("logItem", "auth::processLogin -> response token empty");
|
||||
return reject();
|
||||
}
|
||||
|
||||
if (token.iss != "ayanova.com") {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"auth::processLogin -> token invalid (iss): " + token.iss
|
||||
);
|
||||
return Promise.reject();
|
||||
}
|
||||
if (token.iss != "ayanova.com") {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"auth::processLogin -> token invalid (iss): " + token.iss
|
||||
);
|
||||
return reject();
|
||||
}
|
||||
|
||||
//Put app relevant items into vuex store so app can use them
|
||||
store.commit("login", {
|
||||
apiToken: response.data.token,
|
||||
authenticated: true,
|
||||
userId: Number(token.id),
|
||||
roles: token["ayanova/roles"]
|
||||
//Put app relevant items into vuex store so app can use them
|
||||
store.commit("login", {
|
||||
apiToken: response.data.token,
|
||||
authenticated: true,
|
||||
userId: Number(token.id),
|
||||
roles: token["ayanova/roles"]
|
||||
});
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 2 - PROCESS LOGIN - CALLING INITIALIZE");
|
||||
|
||||
//Initialize the application
|
||||
initialize().then(() => {
|
||||
store.commit(
|
||||
"logItem",
|
||||
"auth::processLogin -> User " + token.id + " logged in"
|
||||
);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
console.log("STEP 2 - PROCESS LOGIN - CALILNG INITIALIZE");
|
||||
|
||||
//Initialize the application
|
||||
initialize();
|
||||
store.commit(
|
||||
"logItem",
|
||||
"auth::processLogin -> User " + token.id + " logged in"
|
||||
);
|
||||
return Promise.resolve(true);
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function processLogout() {
|
||||
|
||||
Reference in New Issue
Block a user