diff --git a/internal_packages/onboarding/lib/onboarding-store.coffee b/internal_packages/onboarding/lib/onboarding-store.coffee index e2c3aa888..36dd1ec21 100644 --- a/internal_packages/onboarding/lib/onboarding-store.coffee +++ b/internal_packages/onboarding/lib/onboarding-store.coffee @@ -14,7 +14,7 @@ OnboardingStore = Reflux.createStore @_pageStack = [@_page] defaultEnv = if atom.inDevMode() then 'staging' else 'production' - atom.config.set('inbox.env', defaultEnv) unless atom.config.get('inbox.env') + atom.config.set('env', defaultEnv) unless atom.config.get('env') @listenTo Actions.setEnvironment, @_onSetEnvironment @listenTo Actions.moveToPreviousPage, @_onMoveToPreviousPage @@ -29,7 +29,7 @@ OnboardingStore = Reflux.createStore @_error environment: -> - atom.config.get('inbox.env') + atom.config.get('env') connectType: -> @_connectType @@ -60,5 +60,5 @@ OnboardingStore = Reflux.createStore _onSetEnvironment: (env) -> throw new Error("Environment #{env} is not allowed") unless env in ['development', 'staging', 'production'] - atom.config.set('inbox.env', env) + atom.config.set('env', env) @trigger() diff --git a/src/atom.coffee b/src/atom.coffee index 853e0ea78..a7c87ac31 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -570,7 +570,9 @@ class Atom extends Model @displayWindow({maximize}) @commands.add 'atom-workspace', - 'atom-workspace:logout': => @logout() + 'atom-workspace:logout': => + if atom.config.get('inbox') + @logout() @commands.add 'atom-workspace', 'atom-workspace:add-account': => @displayOnboardingWindow('add-account') diff --git a/src/flux/edgehill-api.coffee b/src/flux/edgehill-api.coffee index b83b905be..1c6b80c1d 100644 --- a/src/flux/edgehill-api.coffee +++ b/src/flux/edgehill-api.coffee @@ -8,12 +8,12 @@ async = require 'async' class EdgehillAPI constructor: -> - atom.config.onDidChange('inbox.env', @_onConfigChanged) + atom.config.onDidChange('env', @_onConfigChanged) @_onConfigChanged() @ _onConfigChanged: => - env = atom.config.get('inbox.env') + env = atom.config.get('env') if env is 'development' @APIRoot = "https://edgehill-dev.nilas.com" else if env is 'staging' @@ -52,19 +52,21 @@ class EdgehillAPI "#{root}/connect/#{provider}?login_hint=#{email_address}" getCredentials: -> - atom.config.get('inbox.account') + atom.config.get('edgehill.credentials') setCredentials: (credentials) -> - atom.config.set('inbox.account', credentials) + atom.config.set('edgehill.credentials', credentials) addTokens: (tokens) -> for token in tokens if token.provider is 'inbox' atom.config.set('inbox.token', token.access_token) - @setCredentials({username: token.access_token, password: ''}) if token.provider is 'salesforce' atom.config.set('salesforce.token', token.access_token) + if token.user_identifier? + @setCredentials({username: token.user_identifier, password: ''}) + tokenForProvider: (provider) -> atom.config.get("#{provider}.token") diff --git a/src/flux/inbox-api.coffee b/src/flux/inbox-api.coffee index 6ac965a0e..3e972459b 100644 --- a/src/flux/inbox-api.coffee +++ b/src/flux/inbox-api.coffee @@ -12,7 +12,7 @@ class InboxAPI constructor: -> @_streamingConnections = [] - atom.config.onDidChange('inbox.env', @_onConfigChanged) + atom.config.onDidChange('env', @_onConfigChanged) atom.config.onDidChange('inbox.token', @_onConfigChanged) @_onConfigChanged() @@ -24,7 +24,7 @@ class InboxAPI prev = {@APIToken, @AppID, @APIRoot} @APIToken = atom.config.get('inbox.token') - env = atom.config.get('inbox.env') + env = atom.config.get('env') if env in ['production'] @AppID = 'c96gge1jo29pl2rebcb7utsbp' @APIRoot = 'https://api.nilas.com' diff --git a/src/flux/inbox-long-connection.coffee b/src/flux/inbox-long-connection.coffee index 8a3d3ad36..b5eed414f 100644 --- a/src/flux/inbox-long-connection.coffee +++ b/src/flux/inbox-long-connection.coffee @@ -86,11 +86,10 @@ class InboxLongConnection @_buffer = bufferJSONs[bufferJSONs.length - 1] start: -> + return if not @_inbox.APIToken? return if @_state is InboxLongConnection.State.Ended return if @_req - throw (new Error 'Cannot start polling without auth token.') unless @_inbox.APIToken - console.log("Long Polling Connection: Starting....") @withCursor (cursor) => return if @state is InboxLongConnection.State.Ended