From d55a2af2cda7670d431f020b71bce6c5dbb6c7b8 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Mon, 19 Dec 2016 09:25:07 -0800 Subject: [PATCH] [cloud-api] refactor cloud API routes to use es6 & fix Gmail Auth Summary: This is a refactor of the auth APIs to use async/await. Gmail Auth is pretty confusing and I wanted to make it cleaner to read and easier to use. This is also part of the general API upgrade to modern ES6 This also fixes the Gmail auth error we saw at showcase Test Plan: manual Reviewers: halla, jackie, mark, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3535 --- packages/isomorphic-core/src/auth-helpers.js | 4 ++-- packages/local-sync/src/local-api/routes/auth.js | 4 ++-- pm2-dev.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/isomorphic-core/src/auth-helpers.js b/packages/isomorphic-core/src/auth-helpers.js index e863bd0cb..7b9411d66 100644 --- a/packages/isomorphic-core/src/auth-helpers.js +++ b/packages/isomorphic-core/src/auth-helpers.js @@ -97,7 +97,7 @@ module.exports = { } }, - imapAuthHandler(accountBuildFn) { + imapAuthHandler(upsertAccount) { return (request, reply) => { const dbStub = {}; const connectionChecks = []; @@ -121,7 +121,7 @@ module.exports = { emailAddress: email, connectionSettings: connectionSettings, } - return accountBuildFn(accountParams, connectionCredentials) + return upsertAccount(accountParams, connectionCredentials) }) .then(({account, token}) => { const response = account.toJSON(); diff --git a/packages/local-sync/src/local-api/routes/auth.js b/packages/local-sync/src/local-api/routes/auth.js index e21097141..31661a31a 100644 --- a/packages/local-sync/src/local-api/routes/auth.js +++ b/packages/local-sync/src/local-api/routes/auth.js @@ -3,7 +3,7 @@ const DefaultSyncPolicy = require('../default-sync-policy') const LocalDatabaseConnector = require('../../shared/local-database-connector') const SyncProcessManager = require('../../local-sync-worker/sync-process-manager') -const accountBuildFn = (accountParams, credentials) => { +const upsertAccount = (accountParams, credentials) => { return LocalDatabaseConnector.forShared().then(({Account}) => { accountParams.syncPolicy = DefaultSyncPolicy accountParams.lastSyncCompletions = [] @@ -21,6 +21,6 @@ module.exports = (server) => { method: 'POST', path: '/auth', config: AuthHelpers.imapAuthRouteConfig(), - handler: AuthHelpers.imapAuthHandler(accountBuildFn), + handler: AuthHelpers.imapAuthHandler(upsertAccount), }); } diff --git a/pm2-dev.yml b/pm2-dev.yml index 17b755a1b..4c19a0bf8 100644 --- a/pm2-dev.yml +++ b/pm2-dev.yml @@ -1,5 +1,5 @@ apps: - - script : packages/cloud-api/app.js + - script : packages/cloud-api/app.es6 interpreter : node_modules/.bin/babel-node watch : ["packages"] name : api