fix(account): re-add token if a new one comes in

Summary: fix(account): allow users to reconnect accounts if auth has failed

Test Plan: manual

Reviewers: bengotow, juan

Differential Revision: https://phab.nylas.com/D2663
This commit is contained in:
Evan Morikawa 2016-03-01 16:00:53 -08:00
parent a421ee2a80
commit 11c119393e
5 changed files with 23 additions and 14 deletions

View file

@ -18,6 +18,12 @@ class AccountChoosePage extends React.Component
componentWillUnmount: ->
@_usub?()
componentDidMount: ->
if @props.pageData.provider
providerData = _.findWhere(Providers, name: @props.pageData.provider)
if providerData
@_onChooseProvider(providerData)
render: =>
<div className="page account-choose">
<div className="quit" onClick={ -> OnboardingActions.closeWindow() }>

View file

@ -51,14 +51,14 @@ describe "NylasAPI", ->
spyOn(Actions, 'postNotification')
NylasAPI._handleAuthenticationFailure('/threads/1234', 'token')
expect(Actions.postNotification).toHaveBeenCalled()
expect(Actions.postNotification.mostRecentCall.args[0].message.trim()).toEqual("Nylas can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please remove the account and sign in again.")
expect(Actions.postNotification.mostRecentCall.args[0].message.trim()).toEqual("Nylas N1 can no longer authenticate with your mail provider. You will not be able to send or receive mail. Please click here to reconnect your account.")
it "should include the email address if possible", ->
spyOn(AccountStore, 'tokenForAccountId').andReturn('token')
spyOn(Actions, 'postNotification')
NylasAPI._handleAuthenticationFailure('/threads/1234', 'token')
expect(Actions.postNotification).toHaveBeenCalled()
expect(Actions.postNotification.mostRecentCall.args[0].message.trim()).toEqual("Nylas can no longer authenticate with #{AccountStore.accounts()[0].emailAddress}. You will not be able to send or receive mail. Please remove the account and sign in again.")
expect(Actions.postNotification.mostRecentCall.args[0].message.trim()).toEqual("Nylas N1 can no longer authenticate with #{AccountStore.accounts()[0].emailAddress}. You will not be able to send or receive mail. Please click here to reconnect your account.")
describe "handleModelResponse", ->
beforeEach ->

View file

@ -271,7 +271,8 @@ class Application
nylasWindow ?= @windowManager.focusedWindow()
nylasWindow?.browserWindow.inspectElement(x, y)
@on 'application:add-account', => @windowManager.ensureOnboardingWindow()
@on 'application:add-account', (provider) =>
@windowManager.ensureOnboardingWindow({provider})
@on 'application:new-message', => @windowManager.sendToMainWindow('new-message')
@on 'application:view-help', =>
url = 'https://nylas.zendesk.com/hc/en-us/sections/203638587-N1'
@ -389,8 +390,8 @@ class Application
win = BrowserWindow.fromWebContents(event.sender)
@applicationMenu.update(win, template, keystrokesByCommand)
ipcMain.on 'command', (event, command) =>
@emit(command)
ipcMain.on 'command', (event, command, args...) =>
@emit(command, args...)
ipcMain.on 'window-command', (event, command, args...) ->
win = BrowserWindow.fromWebContents(event.sender)

View file

@ -133,7 +133,7 @@ class WindowManager
# Returns a new onboarding window
#
ensureOnboardingWindow: ({welcome}={}) ->
ensureOnboardingWindow: ({welcome, provider}={}) ->
existing = @onboardingWindow()
if existing
existing.focus()
@ -147,6 +147,7 @@ class WindowManager
windowProps:
page: 'account-choose'
uniqueId: 'onboarding'
pageData: {provider}
if welcome
options.title = "Welcome to N1"

View file

@ -129,9 +129,9 @@ class NylasAPI
if NylasEnv.isMainWindow()
Actions.notificationActionTaken.listen ({notification, action}) ->
if action.id is '401:unlink'
Actions.switchPreferencesTab('Accounts')
Actions.openPreferences()
if action.id is '401:reconnect'
ipc = require('electron').ipcRenderer
ipc.send('command', 'application:add-account', action.provider)
_onConfigChanged: =>
prev = {@AppID, @APIRoot, @APITokens}
@ -245,15 +245,16 @@ class NylasAPI
type: 'error'
tag: '401'
sticky: true
message: "Nylas can no longer authenticate with #{email}. You
will not be able to send or receive mail. Please remove the
account and sign in again.",
message: "Nylas N1 can no longer authenticate with #{email}. You
will not be able to send or receive mail. Please click
here to reconnect your account.",
icon: 'fa-sign-out'
actions: [{
default: true
dismisses: true
label: 'Unlink'
id: '401:unlink'
label: 'Reconnect'
provider: account?.provider ? ""
id: '401:reconnect'
}]
return Promise.resolve()