So I've started to experiment with replication last weekend (meaning:
newbie), unfortunately without success with a very simple case: Maybe I'm
still missing some important concept?
In my test, I just wanted to be able to generate some data (with a user
logged in), then go to another device, and be able to see this data using
the same user (after logging in).
Here's the scenario:
-Couchbase Lite based app using custom authentication: this is working
already, I get the session cookies and I'm able to see the documents synced
the Couchbase server.
Test 1:
-User A fires the app in his first device, registers himself, the app calls:
[push/pull setCookieNamed:@"SyncGatewaySession" withValue:sessionValue path
:nil expirationDate:nil secure:NO];
He gets his own document created with a [database documentWithID:
hisUniqueUsername];
The following replication methods are called:
- (void)defineSync
{
pull = [_database createPullReplication:_remoteURL];
push = [_database createPushReplication:_remoteURL];
pull.continuous = push.continuous = YES;
[self listenForReplicationEvents:push];
[self listenForReplicationEvents:pull];
}
- (void)startSync {
[pull start];
[push start];
}
The document gets created and synced to database. In my shadow bucket it
looks something like this:
{
"type": "contacInfo",
"username": "userA"
}
So the user enters some data, and saves the document, e.g.:
{
"type": "contacInfo",
"blobData" : "Some user data",
"username": "userA"
}
I can see in the logs that the replication works as soon as the [save]
method is called, so far everything as expected...
Now, you might have predicted this one: After running the same pattern in
another device (but skipping registration and using this same user), I
realise that I created a conflict because: the initDocumentWith ID will
generate a new document, but with the same ID. This document is newer, so I
believe sync gateway will make this the winning revision from the conflict,
and I won't be able to see "blobData" in the second device.
So I went ahead and changed the order of things:
Test 2-
After logging in, I first wait for the replication to complete, and just
then I call [database existingDocumentWithID], in the hope that now I'll
get the document instead of creating a new one.
But no, I'm still not able to find the document and therefore I have no
access to the "blobData" generated from the first device.
Okay, maybe I could create another document with "blobData" associating the
owner to his user's unique ID and find it with a query, but it feels more
like a workaround (?).
And already to advance / confirm: right now I have basically nothing in my
sync function - but if I ever call requireUser("userA") there, this will
lookup the current session_id from the request, and see if it matches with
the user's who is doing this request, thus one can be sure that sync
gateway knows whether the client doing request to change the document, is
who he claims to be, correct? In other words, if the session gets
validated, I can be confident that "requireUser()" will block any updates
not coming from that user, correct ?
Anybody could shed some light here?
Thanks in advance,
Thiago
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/ddfb322e-11f2-48fc-8d63-89b6bb65c63a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.