Comments (6)
I've been giving some thought to this and we definitely need a user database manager. This is not only to keep the design docs up to date when they change, but also to add and remove user roles and change permissions.
from superlogin.
When you create a user or add a new database to an existing user, SuperLogin automatically seeds the design docs that you specify in your config. If you update the design docs later you will need to manually reseed them.
Maintaining DBs seeded with the correct design docs as they update is complex and outside the scope of SuperLogin. I would love to see an external plugin to help with the tedious tasks of managing userDBs.
SL uses pouchdb-seed-design behind the scenes.
from superlogin.
So, while trying to solve this for my app, I went through the code of addUserDB and pouch-seed-design. Apparently, this flow is already taking care of -
- Ignoring existing DBs.
- Seeding only changed docs in the said DB.
For me, simply invokingsuperlogin.addUserDB
in thelogin
event should work, as it will not recreate the DB but still update only changed/new design docs.
However, I think with this minimal logic, Superlogin can internally take care of this need without much complication.
Please provide your thoughts. I can request a PR.
This feature is a certain requirement for my application, one way or the other. Its a given thing that as new features are added, user DBs will have new designs and modifications. I'd hope you could allocate some of your time to reevaluate this for Superlogin.
from superlogin.
We also have the need for this, if only to more easily develop a validate_doc_update
function.
So I've started on a script we can run as util. A pitty is that most of it's logic is almost a direct copy of user.js
's addUserDBs
and dbauth/index.js
's addUserDB
functions. It currently only creates & updates shared databases and it doesn't update existing sessions. (See my question here: #152 (comment))
const SuperLogin = require('superlogin');
const superloginConfig = require('../superlogin.config.js');
const DBAuth = require('superlogin/lib/dbauth');
const PouchDB = require('pouchdb');
const seed = require('pouchdb-seed-design');
const util = require('superlogin/lib/util');
const superlogin = new SuperLogin(superloginConfig);
const { config } = superlogin;
const dbAuth = new DBAuth(config/* , userDB, couchAuthDB*/);
if (!config.getItem('userDBs.defaultDBs')) {
console.log('no userDBs.defaultDBs defined');
process.exit();
}
const cloudant = config.getItem('dbServer.cloudant');
let adapter;
if (cloudant) {
adapter = require('superlogin/lib/dbauth/cloudant');
} else {
throw new Error('CouchDB not supported');
}
let allDBs = [];
function addDBs(dbs, type) {
if (!Array.isArray(dbs)) return;
dbs.forEach(dbName => {
const dbConfig = dbAuth.getDBConfig(dbName);
dbConfig.type = type; // override type
if (type !== 'shared') return; // private not supported yet
allDBs.push(dbConfig);
});
}
addDBs(config.getItem('userDBs.defaultDBs.private'), 'private');
addDBs(config.getItem('userDBs.defaultDBs.shared'), 'shared');
function updateDBs(dbs) {
console.log('updateDBs: ', dbs);
return asyncIterator(dbs, dbConfig => {
console.log('dbConfig: ', dbConfig);
const { name, adminRoles, memberRoles, designDocs } = dbConfig;
console.log('updating: ', name);
let newDB;
return dbAuth.createDB(name)
.then(response => {
if (response !== false) console.log('Created db: ', name);
newDB = new PouchDB(util.getDBURL(config.getItem('dbServer')) + '/' + name);
return adapter.initSecurity(newDB, adminRoles, memberRoles);
})
.then(() => {
// Seed the design docs
if (designDocs && designDocs instanceof Array) {
// designDocs.forEach(ddName => {
console.log('designDocs: ', designDocs);
return asyncIterator(designDocs, ddName => {
console.log('ddName: ', ddName);
const dDoc = dbAuth.getDesignDoc(ddName);
console.log('dDoc: ', dDoc);
if (dDoc) {
return seed(newDB, dDoc);
} else {
console.warn('Failed to locate design doc: ' + ddName);
}
});
}
});
});
}
updateDBs(allDBs).then(() => {
process.exit();
});
function asyncIterator(args, callback) {
return new Promise((resolve, reject) => {
const results = [];
if (args.length === 0) resolve(results);
const clone = [...args];
function loop(arg) {
callback(arg).then(function (result) {
results.push(result);
if (clone.length > 0) {
loop(clone.shift());
} else {
resolve(results);
}
});
}
loop(clone.shift());
});
}
from superlogin.
I think I've found a way to update current session API keys in databases and re-use the existing dbauth/index.js
's addUserDB
function. The following function should update all databases according to configuration. Because everything happens in series (not parallel) this should also work for bigger projects.
https://gist.github.com/peteruithoven/b8fd1f60ae526c849479e50a38709590#file-updatedbs-js
Curious what you guys think.
from superlogin.
Would it be interesting to add this to the general API, just like removeExpiredKeys?
from superlogin.
Related Issues (20)
- How can I remove confirmPassword requirement?
- Validation failed HOT 8
- Validation failed HOT 1
- Calling /auth/session with authorization header is returning unauthorized HOT 1
- Use template-literal instead of EJS
- user-db-added event doesn't get emitted HOT 1
- New release? HOT 13
- Validation Failed HOT 1
- Register vaildation failed HOT 18
- Mandatory Migration from Cloudant to BlueMix not compatible with Superlogin HOT 1
- Superlogin with CouchDB crypto.pbkdf2 "digest" argument required HOT 1
- how to add profile data with registration?
- removeUser not working
- Live demo isn't working HOT 1
- Forgot Password function
- TypeError: Cannot read property 'valid' of undefined at Function.PouchDB.parseAdapter
- Howto: use superlogin with current nodejs HOT 6
- Set a Doc create limit per user
- super login spaming console with errors
- Graphql
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superlogin.