cache auth token to prevent race condition on set
This commit is contained in:
parent
cae8e3701f
commit
da8ed48fa7
2 changed files with 13 additions and 5 deletions
|
@ -22,4 +22,4 @@
|
|||
"lbrySettings": {
|
||||
"lbrynetDaemonVersion": "0.14.2"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -113,16 +113,24 @@ lbryio.call = function(resource, action, params = {}, method = "get") {
|
|||
});
|
||||
};
|
||||
|
||||
lbryio._authToken = null;
|
||||
|
||||
lbryio.getAuthToken = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.once("auth-token-response", (event, token) => {
|
||||
return resolve(token);
|
||||
});
|
||||
ipcRenderer.send("get-auth-token");
|
||||
if (lbryio._authToken) {
|
||||
resolve(lbryio._authToken);
|
||||
} else {
|
||||
ipcRenderer.once("auth-token-response", (event, token) => {
|
||||
lbryio._authToken = token;
|
||||
return resolve(token);
|
||||
});
|
||||
ipcRenderer.send("get-auth-token");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
lbryio.setAuthToken = token => {
|
||||
lbryio._authToken = token ? token.toString().trim() : null;
|
||||
ipcRenderer.send("set-auth-token", token);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue