From a421ee2a80118758bc3ab0be67690ae26ac589e8 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Tue, 1 Mar 2016 15:33:02 -0800 Subject: [PATCH] fix(account): re-add token if a new one comes in --- src/flux/stores/account-store.coffee | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/flux/stores/account-store.coffee b/src/flux/stores/account-store.coffee index d63b1b771..78c2fcd74 100644 --- a/src/flux/stores/account-store.coffee +++ b/src/flux/stores/account-store.coffee @@ -101,13 +101,19 @@ class AccountStore extends NylasStore console.error("Returned account data is invalid", json) console.log JSON.stringify(json) throw new Error("Returned account data is invalid") - return if @_tokens[json.id] + @_load() @_tokens[json.id] = json.auth_token - account = (new Account).fromJSON(json) @_caches = {} - @_accounts.push(account) + existingIdx = _.findIndex @_accounts, (a) -> a.id is json.id + if existingIdx is -1 + account = (new Account).fromJSON(json) + @_accounts.push(account) + else + account = @_accounts[existingIdx] + account.fromJSON(json) + @_save() @_trigger()