Open nijakobius opened 6 years ago
Hi @nielsjakob, thanks very much for your detailed report.
I have difficulties figuring out what your problem is, also maybe because I don't Cloudant. I will think about it and come back to you if I understand what is going on.
In the meantime, would you mind:
getSession()
Thank you in advance.
Thanks for your reply, @ptitjes
When I encounter the problem described in my original post, I get the normal browser authentication popup. When I type in my login info, the session gets stored and everything. So while it doesn't work exactly how it should, with this workaround, it's fine for testing on my computer.
Also, I found out that after compiling my PhoneGap app and running it on iOS and Android, it works as expected. It's really just when I run it on PhoneGap's local server.
@nielsjakob If you have the browser authentication popup, this means you have Basic Authentication activated on you database. You might want to disable it and just use Cookie Authentication (+ SSL on production server). I think that would solve your problem.
Is this something that's done in new PouchDB()
? Some header I have to set?
remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE', {
ajax: { headers: { authorization: ??? } }
});
@nielsjakob Sorry for the late reply.
To disable Basic Authentication on your remote database, you must modify the configuration of your remote CouchDB database host.
If you cannot disable it (which maybe you can't on Cloudant), then in order to suppress the authentication popup on the client side, try to add some skip_setup
and auth
options to the PouchDB constructor call:
remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE', {
// to disable contacting the database before logging (and show the popup)
skip_setup: true,
// to configure the Basic Authentication credentials
auth: {
username: 'username',
password: 'password'
}
});
Trying to implement a login system with this plugin (in PhoneGap):
Code
remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE');
remoteDB.logIn('USER', 'PASSWORD').then(function(response) {
console.log(response);
});
remoteDB.getSession(function (error, response) {
console.log(response);
});
Current Behaviour
It works if I open the index.html from the macOS Finder, such that the address bar reads
file:///Users/USER/Documents/pouchdblogin/www/index.html
.However, if I run it via PhoneGap (
http://192.168.0.3:3000/
), the login doesn't seem to work:In both cases, the logIn response is
But the getSession responses are different:
1. For
file:///..........
:-> Expected behaviour
2. but for
http://192.168.0.3:3000/
it is:-> Login didn't work properly
Am I doing something wrong?
Environment