mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 08:16:09 +08:00
[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
This commit is contained in:
parent
5810bb6b79
commit
d55a2af2cd
|
@ -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();
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue