mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 05:06:53 +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'
|
_ = require 'underscore'
|
||||||
{ipcRenderer, dialog, remote} = require 'electron'
|
{ipcRenderer, dialog, remote} = require 'electron'
|
||||||
{RetinaImg} = require 'nylas-component-kit'
|
{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'
|
OnboardingActions = require './onboarding-actions'
|
||||||
NylasApiEnvironmentStore = require './nylas-api-environment-store'
|
NylasApiEnvironmentStore = require './nylas-api-environment-store'
|
||||||
|
@ -318,6 +318,10 @@ class AccountSettingsPage extends React.Component
|
||||||
data.settings[k] = v
|
data.settings[k] = v
|
||||||
data.provider = @state.provider.name
|
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
|
# handle special case for exchange/outlook/hotmail username field
|
||||||
if data.provider in ['exchange','outlook','hotmail'] and not data.settings.username?.trim().length
|
if data.provider in ['exchange','outlook','hotmail'] and not data.settings.username?.trim().length
|
||||||
data.settings.username = data.email
|
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
|
# 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
|
# Otherwise process the error message from the server and highlight UI as needed
|
||||||
NylasAPI.makeRequest
|
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'
|
method: 'POST'
|
||||||
body: data
|
body: data
|
||||||
returnsModel: false
|
returnsModel: false
|
||||||
|
@ -389,6 +393,15 @@ class AccountSettingsPage extends React.Component
|
||||||
pageNumber = @state.pageNumber
|
pageNumber = @state.pageNumber
|
||||||
errorFieldNames = err.body?.missing_fields || err.body?.missing_settings
|
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
|
if errorFieldNames
|
||||||
{pageNumber, errorMessage} = @_stateForMissingFieldNames(errorFieldNames)
|
{pageNumber, errorMessage} = @_stateForMissingFieldNames(errorFieldNames)
|
||||||
if err.statusCode is -123 # timeout
|
if err.statusCode is -123 # timeout
|
||||||
|
|
|
@ -13,6 +13,7 @@ class APIError extends Error
|
||||||
@requestOptions ?= @response?.requestOptions
|
@requestOptions ?= @response?.requestOptions
|
||||||
@name = "APIError"
|
@name = "APIError"
|
||||||
@message = @body?.message ? @body ? @error?.toString?()
|
@message = @body?.message ? @body ? @error?.toString?()
|
||||||
|
@errorTitle = @error?.toString?()
|
||||||
|
|
||||||
class TimeoutError extends Error
|
class TimeoutError extends Error
|
||||||
constructor: ->
|
constructor: ->
|
||||||
|
|
Loading…
Reference in a new issue