Skip to content

Commit

Permalink
Changed API calls to use cookie if been set
Browse files Browse the repository at this point in the history
 fixed loader showing on logged out
  • Loading branch information
lukealford committed Apr 3, 2019
1 parent 571f9f2 commit d96b9ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ div .string {
}

#loader{
display: block;
display: none;
text-align: center;
width: 50%;
margin: 0 auto;
Expand Down
27 changes: 24 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ unhandled();
require('electron-context-menu')({
prepend: (params, browserWindow) => [{}]
});

let hasCookie = false;
const store = new Store();
global.abb = request.jar();


// migrate creds from store to OS keychain
const migrate = async () => {
if (!!store.get('username') && (!!store.get('password'))) {
Expand Down Expand Up @@ -199,12 +200,31 @@ const loggedOut = () => {
tray.setToolTip('Login to check your usage....');
}

const checkAbbCookie = () => {
return new Promise((resolve, reject) => {
if(!hasCookie){
resolve(false);
}else{
resolve(true);
}
});

}

const updateData = async () => {
loggedIn();
if (!!creds.account && !!creds.password) {
let login = await abbLogin(creds.account,creds.password);

let cookieCheck = await checkAbbCookie();
console.log(cookieCheck);
if(cookieCheck === false){
let login = await abbLogin(creds.account,creds.password);

}
let service = await getCustomerData();
let result = await getUsage(service.service_id);


console.log(service,result);

let usage = {}
Expand Down Expand Up @@ -258,7 +278,7 @@ const abbLogin = (user,pass) =>{
reject(res);
}
else{

hasCookie = true;
resolve(res);
}
}
Expand Down Expand Up @@ -342,6 +362,7 @@ const logOut = async () => {
await deletePassword('AUNT', creds.account);
creds.account = null;
creds.password = null;
hasCookie = false;
} catch (e) {
sendMessage('asynchronous-message', 'error', 'deleting Account and Password failed')
console.log(e);
Expand Down

0 comments on commit d96b9ab

Please sign in to comment.