1
0
Fork 0
mirror of synced 2024-06-30 03:50:37 +12:00

cookie based auth for deployment

This commit is contained in:
Martin McKeaveney 2020-10-19 00:05:25 +01:00
parent 5db3c03ee9
commit cdf82cf479

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)