agateblue / tempo

Your personal diary and mood tracker
GNU Affero General Public License v3.0
106 stars 12 forks source link

Cannot sync with CouchDB #17

Closed dskrad closed 2 years ago

dskrad commented 2 years ago

I setup my CouchDB server on my home PC using docker. It is up and running, and I created a "tempo" database all ready to sync. However I cannot get tempo to sync. I get a "Sync OK!" message when I input my database information (I had to unblock insecure content on Vivaldi since I'm just using my local IP with insecure http://).

I checked developer console. It seems I get a 200 back for the _session request (which is sending my username and password in the request header). That's why I get a "Sync OK" message in my browser page.

When I try to actually sync, I get 401 unauthorized. It seems the credentials are not being sent in the request headers. Any help would be appreciated. Thanks.

dskrad commented 2 years ago

After more investigating, I found that the cookie sent by CouchDB is not being set because of the SameSite=Lax setting, which is the default. I went into CouchDB settings and added the following key [couchdb_httpd_auth] same_site = None This changed the cookie's SameSite attribute, but Vivaldi is still not setting the cookie because Secure is not set on the cookie. This seems to be an issue with running a CouchDB on localhost with http instead of https. Looking into possible solutions.

agateblue commented 2 years ago

Yes, I think running CouchDB on a local, non https URL can cause issues with synchronisation, especially if you are using Tempo from a public, https URL. Similar issue: https://stackoverflow.com/questions/68609006/cookie-authentication-couchdb-on-localhost

If I remember correctly, this did work when both CouchDB and Tempo were served locally. Would you mind trying this, e.g running Tempo in development (instructions at https://github.com/agateblue/tempo#project-setup) and see if it works that way?

dskrad commented 2 years ago

I finally got CouchDB installation working properly by setting up HAproxy as a reverse proxy as recommended on CouchDB docs. As a bonus, my other services on that machine are all now available via my own domain name, and secured by TLS using Cloudflare DNS and free HTTPS certificate. Syncing like a champ now.

agateblue commented 2 years ago

Thank you for letting us now :)