mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 11:52:34 +08:00
feat(auth): Provide reauth param to handle changed server endpoints
Summary: Notify the backend when auth is a reauth of an existing account by providing the `accountId`. This lets the backend differentiate between a new auth (where a new account will be created if the server endpoints don't match) and a re-auth (where the auth will fail on server endpoint mismatch, prompting the user). Test Plan: manual Reviewers: juan, evan, bengotow Reviewed By: bengotow Subscribers: mg, spang, kav-ya Differential Revision: https://phab.nylas.com/D2833
This commit is contained in:
parent
5d96fb227f
commit
2edc2e5c32
2 changed files with 16 additions and 2 deletions
|
@ -3,7 +3,7 @@ ReactDOM = require 'react-dom'
|
|||
_ = require 'underscore'
|
||||
{ipcRenderer, dialog, remote} = require 'electron'
|
||||
{RetinaImg} = require 'nylas-component-kit'
|
||||
{RegExpUtils, EdgehillAPI, NylasAPI, APIError, Actions} = require 'nylas-exports'
|
||||
{RegExpUtils, EdgehillAPI, NylasAPI, APIError, Actions, AccountStore} = require 'nylas-exports'
|
||||
|
||||
OnboardingActions = require './onboarding-actions'
|
||||
NylasApiEnvironmentStore = require './nylas-api-environment-store'
|
||||
|
@ -318,6 +318,10 @@ class AccountSettingsPage extends React.Component
|
|||
data.settings[k] = v
|
||||
data.provider = @state.provider.name
|
||||
|
||||
# if there's an account with this email, get the ID for it to notify the backend of re-auth
|
||||
account = AccountStore.accountForEmail(email)
|
||||
reauthParam = if account then "&reauth=#{account.id}" else ""
|
||||
|
||||
# handle special case for exchange/outlook/hotmail username field
|
||||
if data.provider in ['exchange','outlook','hotmail'] and not data.settings.username?.trim().length
|
||||
data.settings.username = data.email
|
||||
|
@ -328,7 +332,7 @@ class AccountSettingsPage extends React.Component
|
|||
# If this succeeds, send the received code to N1 server to register the account
|
||||
# Otherwise process the error message from the server and highlight UI as needed
|
||||
NylasAPI.makeRequest
|
||||
path: "/auth?client_id=#{NylasAPI.AppID}&n1_id=#{NylasEnv.config.get('updateIdentity')}"
|
||||
path: "/auth?client_id=#{NylasAPI.AppID}&n1_id=#{NylasEnv.config.get('updateIdentity')}#{reauthParam}"
|
||||
method: 'POST'
|
||||
body: data
|
||||
returnsModel: false
|
||||
|
@ -389,6 +393,15 @@ class AccountSettingsPage extends React.Component
|
|||
pageNumber = @state.pageNumber
|
||||
errorFieldNames = err.body?.missing_fields || err.body?.missing_settings
|
||||
|
||||
if err.errorTitle is "setting_update_error"
|
||||
choice = dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||
type: 'info',
|
||||
buttons: ['Okay'],
|
||||
title: 'Confirm',
|
||||
message: 'The IMAP/SMTP servers for this account do not match our records. Please verify that any server names you entered are correct. If your IMAP/SMTP server has changed, first remove this account from N1, then try logging in again.'
|
||||
})
|
||||
OnboardingActions.moveToPage("account-settings")
|
||||
|
||||
if errorFieldNames
|
||||
{pageNumber, errorMessage} = @_stateForMissingFieldNames(errorFieldNames)
|
||||
if err.statusCode is -123 # timeout
|
||||
|
|
|
@ -13,6 +13,7 @@ class APIError extends Error
|
|||
@requestOptions ?= @response?.requestOptions
|
||||
@name = "APIError"
|
||||
@message = @body?.message ? @body ? @error?.toString?()
|
||||
@errorTitle = @error?.toString?()
|
||||
|
||||
class TimeoutError extends Error
|
||||
constructor: ->
|
||||
|
|
Loading…
Reference in a new issue