Logout/Login with continous replication not working as expected

20 views
Skip to first unread message

Carsten Fregin

unread,
Aug 23, 2016, 11:19:07 AM8/23/16
to Couchbase Mobile
Hi.
I am trying to get user profiles up running. I have that sync-func on my sync_gateway server:

if (doc.type == "profile") {

 var user = doc.owner;

 requireUser(user);

 log("Access user:" + doc.owner + " to channel:" + "profile-" + doc.owner);

 access(doc.owner, "profile-" + doc.owner);

 channel("profile-" + doc.owner);

}


As I am using oauth2 against an existing backent I choosed to use a node.js server to verify email/pwd and then create/update that user over sync_gateway port 4985 and after that a session. With that session I create a profile document on port 4984. I return the sync_gateway create session response to the app.

In the app I create a pull/push and start replication with:
self.pull.setCookieNamed(cookie_name, withValue: session_id, path: nil, expirationDate:date, secure: false)

self.pull.continuous = true

self.pull.start()


Now my problem/misunderstanding?
If I want to login as a different User, I stop the current replication, login with the new credentials, get a new session and recreate the replications with the new sessions. My problem then: the profile document of the new user is not pulled/synced. 

When I set the continuous to false I gat a different behaviour. The first sync does not fetch the profile document. After starting the sync again, it is fetched. Logging in as a different user now does fetch the new profile document and I end up with two profile documents in my local database (which is an expected behaviour),

So, to conclude:
What is the "right" way to handle User-specific profile documents in case of multiple logins/logouts.

Thank you!

Reply all
Reply to author
Forward
0 new messages