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
|
@ -113,16 +113,24 @@ lbryio.call = function(resource, action, params = {}, method = "get") {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lbryio._authToken = null;
|
||||||
|
|
||||||
lbryio.getAuthToken = () => {
|
lbryio.getAuthToken = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (lbryio._authToken) {
|
||||||
|
resolve(lbryio._authToken);
|
||||||
|
} else {
|
||||||
ipcRenderer.once("auth-token-response", (event, token) => {
|
ipcRenderer.once("auth-token-response", (event, token) => {
|
||||||
|
lbryio._authToken = token;
|
||||||
return resolve(token);
|
return resolve(token);
|
||||||
});
|
});
|
||||||
ipcRenderer.send("get-auth-token");
|
ipcRenderer.send("get-auth-token");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
lbryio.setAuthToken = token => {
|
lbryio.setAuthToken = token => {
|
||||||
|
lbryio._authToken = token ? token.toString().trim() : null;
|
||||||
ipcRenderer.send("set-auth-token", token);
|
ipcRenderer.send("set-auth-token", token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue