Using PouchDb and CryptoPouch in an Ionic 2 app fails when trying to encrypt a database.
I have created this project to demonstrate the issue.
The basic usage is this:
import * as PouchDB from 'pouchdb';
import * as CryptoPouch from 'crypto-pouch';
export class TutorialPage {
constructor(public navCtrl: NavController, public menu: MenuController, translate: TranslateService) {
PouchDB.plugin(CryptoPouch);
var db = new PouchDB('kittens');
var password = "password";
db.crypto(password);
// db.crypto(password).then(function () {
// return db.put({_id: 'foo', bar: 'baz'});
// }).then(function () {
// return db.get('foo');
// }).then(function (doc) {
// console.log('decrypted', doc);
// return db.removeCrypto();
// }).then(function () {
// return db.get('foo');
// }).then(function (doc) {
// console.log('encrypted', doc);
// })
This code will run, but just doing db.crypto(password) apparently will do nothing.
According to this StackOverflow answer,
This is needed:
db.crypto(password).then(function () {
// <-- encryption set up
})
However, trying this, for example by uncommenting the above commented out code will cause this runtime error:
EXCEPTION: Error in ./MyApp class MyApp - inline template:16:2 caused by: undefined is not an object (evaluating 'db.crypto(password).then')
Not sure why the first db.crypto(password) will work but the db.crypto(password).then will not.
This may be a setup issue similar to this issue where the answer was to standalone/crypto-pouch, but I'm not sure how that relates to an Ionic 2 project.
Using PouchDb and CryptoPouch in an Ionic 2 app fails when trying to encrypt a database. I have created this project to demonstrate the issue.
The basic usage is this:
This code will run, but just doing
db.crypto(password)
apparently will do nothing. According to this StackOverflow answer, This is needed:However, trying this, for example by uncommenting the above commented out code will cause this runtime error:
Not sure why the first
db.crypto(password)
will work but thedb.crypto(password).then
will not.This may be a setup issue similar to this issue where the answer was to standalone/crypto-pouch, but I'm not sure how that relates to an Ionic 2 project.