fransyozef
fransyozef

Reputation: 574

couchDB / pouchDB / IONIC best practice

I want to create an app with IONIC to manage buildings. A user can hold multiple buildings. Each building has rooms. Each rooms has logs. Each user is a member of a cooperation.

For many years I've used LAMP. Now moving to mobile and made some IONIC apps. With 2 apps I've used SQLite as datastore on the mobile device.

But now I've read up on couchDB and pouchDB and really like the concept and the sync option. So now I'm looking into this to use as my datastore (on the mobile and also on the backend).

Now I've got 2 major questions/concerns:

  1. Authentication

In my LAMP situation, I usually have an SESSION (table which holds the sessions strings and userID) and an USERS table. When the user logs in, the user is lookup in the USERS table, and a session string is created and saved with the userID.

Now each time a request is made to the server (for example update data), the session string is also supplied and matched to the SESSION table and retrieve the correct user. From that point on, I can validate if the post is valid and the data also belongs to the correct user.

Back to couchDB, I know there is a cookie management in couchDB (http://guide.couchdb.org/editions/1/en/security.html). So here I can validate if an user exists and validate the credentials. Now the app can send requests with a cookie.

  1. Fetch/Update the right data
    In my LAMP situation, I always knew which data belongs to which user. And the back end always checks if this is correct.

In my couchDB I want to create database and each document is an user with all the data. So now here comes the problem. I can validate an user in couchDB, put there's no way to validate the data (at least as far I know of) that it belongs to the right user. My goal is that the mobile device syncs the document to the couchDB server.

  1. Database structure
    At first I wanted to create a database per user. But this is not scalable. Also an user is an member of a cooperation. I also need to generate reports per cooperation/user. So now I was thinking to create a database per cooperation. But now the problem is, when a user login, I need to know which database to connect to lookup the user data. Now I want to use 1 database and each document is an user and holds all data (buildings/logs).

Has anybody got some other suggestions/resources on this approach?

Upvotes: 0

Views: 500

Answers (1)

kabus
kabus

Reputation: 909

You can try couchdb in combination with superlogin:

SuperLogin is a full-featured NodeJS/Express user authentication solution for APIs and Single Page Apps (SPA) using CouchDB or Cloudant.

github

Tutorial

Upvotes: -2

Related Questions