1
votes

I'm currently working on an offline-first mobile application. I'm using PouchDB and an CouchDB remote server.

I've used the login and create user functions from: https://github.com/nolanlawson/pouchdb-authentication

What I want to achieve is, to save the users username and password (if the 'remember me' option is selected). so when you restart your mobile device and open the app, it opens logged in to your account rather then having to login again. (a bit like facebook/twitter app).

Is there anyone who can help me achieve this? I'm open for all little bits of help/knowledge!

2

2 Answers

3
votes

You could store username and password in a document with the _local/ prefix for the _id. Those kinds of documents are not synced when a replication is started. More info in the PouchDB docs.

Another solution would be to use just store the auth token you receive via cookie authentication. You can configure CouchDB to issue persistent cookies and you can set the timeout to longer periods (see the documentation). This is more secure, as you won't store the password in clear text anywhere.

1
votes

Here's how I did it:

At start I check localstorage for previous valid username

tmp1 = $localstorage.get('mymarker', '???');
if (tmp1 != '???') {
   $scope.userdata.username = tmp1
   skipusername = true;
}

Then at login I prefill username (actually skip it completely) and just ask for password.

If credentials where valid I store the user name like so:

 $localstorage.set('mymarker', $scope.userdata.username);

I also will add password (CryptoJS works great for encryption) and force a once a day rule to type password again. Hope this some any help.