Prevent auth failures for Zotero Storage requests after relinking
If you unlinked your sync account and then relinked, the ZFS storage controller would still have the old API key and file-sync requests would fail. Since that was never supposed to be possible, it resulted in "Group with libraryID 1 does not exist" errors during file syncing until you restarted the app.
This commit is contained in:
parent
7c91f37348
commit
4ca3843ce7
2 changed files with 21 additions and 1 deletions
|
@ -837,7 +837,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
},
|
||||
|
||||
|
||||
// TODO: Call on API key change
|
||||
this.resetStorageController = function (mode) {
|
||||
delete _storageControllers[mode];
|
||||
},
|
||||
|
@ -1672,6 +1671,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
|
||||
|
||||
this.deleteAPIKey = Zotero.Promise.coroutine(function* (){
|
||||
this.resetStorageController('zfs');
|
||||
var apiKey = yield Zotero.Sync.Data.Local.getAPIKey();
|
||||
var client = this.getAPIClient({apiKey});
|
||||
Zotero.Sync.Data.Local.setAPIKey();
|
||||
|
|
|
@ -90,6 +90,26 @@ describe("Sync Preferences", function () {
|
|||
assert.equal(doc.getElementById('sync-authorized').getAttribute('hidden'), 'true');
|
||||
});
|
||||
|
||||
it("should reset the storage controller when unlinking", async function () {
|
||||
await setCredentials("Username", "correctPassword");
|
||||
await assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey);
|
||||
|
||||
var options = {
|
||||
apiClient: Zotero.Sync.Runner.getAPIClient({ apiKey })
|
||||
};
|
||||
var controller = Zotero.Sync.Runner.getStorageController('zfs', options);
|
||||
var apiKey1 = controller.apiClient.apiKey;
|
||||
|
||||
await win.Zotero_Preferences.Sync.unlinkAccount(false);
|
||||
await setCredentials("Username", "correctPassword");
|
||||
|
||||
options = {
|
||||
apiClient: Zotero.Sync.Runner.getAPIClient({ apiKey })
|
||||
};
|
||||
controller = Zotero.Sync.Runner.getStorageController('zfs', options);
|
||||
assert.notEqual(controller.apiClient.apiKey, apiKey1);
|
||||
});
|
||||
|
||||
it("should not unlink on pressing cancel", function* () {
|
||||
yield setCredentials("Username", "correctPassword");
|
||||
|
||||
|
|
Loading…
Reference in a new issue