cookie based auth for deployment

This commit is contained in:
Martin McKeaveney 2020-10-19 00:05:25 +01:00
parent 3679416322
commit a06c504619
1 changed files with 10 additions and 4 deletions

View File

@ -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)