From cdf82cf479ef08139996444c2e08e16c275eaa9e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 19 Oct 2020 00:05:25 +0100 Subject: [PATCH] cookie based auth for deployment --- .../server/src/api/controllers/deploy/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index 327f820a7e..afbe62454f 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -16,7 +16,7 @@ function replicate(local, remote) { }) } -async function replicateCouch({ instanceId, clientId, credentials }) { +async function replicateCouch({ instanceId, clientId, session }) { const databases = [`client_${clientId}`, "client_app_lookup", instanceId] const replications = databases.map(localDbName => { @@ -24,10 +24,16 @@ async function replicateCouch({ instanceId, clientId, credentials }) { const remoteDb = new CouchDB( `${process.env.DEPLOYMENT_DB_URL}/${localDbName}`, { - auth: { - ...credentials, + fetch: function(url, opts) { + opts.headers.set("Cookie", `${session};`) + return CouchDB.fetch(url, opts) }, } + // { + // auth: { + // ...credentials, + // }, + // } ) return replicate(localDb, remoteDb) @@ -92,7 +98,7 @@ exports.deployApp = async function(ctx) { await replicateCouch({ instanceId: ctx.user.instanceId, clientId, - credentials: credentials.couchDbCreds, + session: credentials.couchDbSession, }) await updateDeploymentQuota(credentials.quota)