Cookie's expiration handling

Hello,

I use Couchbase Lite for Android.
I use cookie authorization in CouchDB. In Couchbase Lite I set cookies by method Replication.setCookie(), and it works fine until they are expired.

I can’t find any API callback, which will notify me that the replication gets unauthorized access error. In logcat I see error that the client is unauthorized, but it happens after ChangeListener notifies me about changes it’s going to process.
How can I check that the cookies are expired and the replication is stuck? Or I have to do it manually?

I see two possible ways to do it:

  • The replicator has a lastError property which you can check in the change listener of the replicator. If it’s a 401, you can renew it.

  • The session endpoint on the (Admin) REST API returns the cookie name, value and expiry date. You could have some logic in your app to automatically renew it according to the expiry date.

James

Hi, @jamiltz

When the method ChangeListener.changed() is called, there is no error by lastError property. Only after this call I see in logcat the message about unauthorized access and I don’t get any notifications from the ChangeListener when the error has happened.

Yes, I see the solution in setting up a timer and do cookie’s update by the timer expiration, but looks a bit strange, because the replication is stopped by this time, but I don’t get any notification from the ChangeListener that state has been changed.

Sorry for the late response. In TodoLite, there is code to catch the 401 Unauthorised from the replication listener and logs out the user. You could use the same method to refresh the session cookie instead.

James