Facebook Log in/Log out

33 views
Skip to first unread message

James Nocentini

unread,
Dec 3, 2014, 9:54:21 AM12/3/14
to mobile-c...@googlegroups.com
I'm using Facebook Login with Couchbase Lite, attempting to do the same set up as TodoLite-iOS (https://github.com/couchbaselabs/ToDoLite-iOS)
When a user logs in, open a new db (with its name being an md5 hash of the user's email).
Set up push/pull replications with authenticator property like so (token is returned from facebook sdk):

pull.authenticator = CBLAuthenticator.facebookAuthenticatorWithToken(token)

When logging out and logging back in with a different account, sync gateway runs the previous replication, thus pulling the data of another user) instead of running the replication with the new user's token. Is there a way to force a replication to be invalidated?
Side question: can couchbase lite run several replications with different authenticators?
In my case logging in or out is irrelevant. It will always run the replication that was setup when the app was first opened and never run the replication of the next user logging in on the device.

Setup replication (upon login):
let syncURL = NSURL(string: kSyncGatewayUrl)
pull
= currentDatabase.createPullReplication(syncURL) // currentDatabase is the user's db (name: md5 of user's email)
pull
.continuous = true

push
= currentDatabase.createPushReplication(syncURL)
push
.continuous = true

Stop replication (when logging out):
pull.stop()
pull
= nil

push
.stop()
push
= nil

Jens Alfke

unread,
Dec 3, 2014, 12:18:01 PM12/3/14
to mobile-c...@googlegroups.com
On Dec 3, 2014, at 6:54 AM, James Nocentini <james.n...@gmail.com> wrote:

When logging out and logging back in with a different account, sync gateway runs the previous replication, thus pulling the data of another user) instead of running the replication with the new user's token. Is there a way to force a replication to be invalidated?

This sounds like a bug; it's probably happening because Facebook-based Gateway auth uses session cookies. The second replication isn't authenticating with the new account because there's still a valid session left over from the previous replication.

You can probably work around this by using the NSHTTPCookieStorage API to remove the cookie named "SyncGatewaySession". This will force the next replication to sign in again, creating a new login session/cookie for the other account.

Side question: can couchbase lite run several replications with different authenticators?

Not currently, due to the above issue — the session cookie is effectively a process-wide global. To fix this I think we'd need to instantiate a separate NSHTTPCookieStorage for each replicator instance. I just filed an issue to cover that.

—Jens
Reply all
Reply to author
Forward
0 new messages