couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Wadholm <>
Subject Re: looking for couchapp examples for managing user authentification
Date Sun, 23 Oct 2011 14:35:46 GMT
Also, after setting the variable for User from an ajax call to _session, instead of merely
checking for the existence of the userCtx, you could check for an actual value:

if(User != undefined || null) {
// Do something for the logged in User
// Else if not logged in, go to login/signup page
} else { + "index.html", target="_self");*

On Oct 23, 2011, at 8:22 AM, Robert Wadholm wrote:

You could use a synchronous AJAX call using jquery on each page (this should be placed before
much of the other js for the page):

url: '/_session?callback=',
dataType: 'json',
async: false,
success: function(session){
User =<>;


On Oct 23, 2011, at 5:08 AM, Alexander Gabriel wrote:

Great, thank you Benoit.

Are there examples of entire applications, where I can see how the username
is fetched after logging in and opening a new html-page?


2011/10/23 Benoit Chesneau <<>>

there are ex of code on github:

On Sunday, October 23, 2011, Alexander Gabriel <<>>
Hi all

This is surely a very basic beginners problem - I am biologist and only
starting to learn programming. It may well be a java script issue and
nothing to do with couchdb.

In my couchapp (
, every page needs to know the
name as that is saved in every file. After logging in I get the user name
like this in every page:

*User = "";   //use global variable to save user name in*
* success : function(r) {*
* userCtx = r.userCtx;*
* if (<>) {*
*                        //save user name in variable*
* User =;*
* } else {*
* //user is not logged in, present the login page*
* + "index.html", target="_self");*
* }*
* }*

There probably are several problems here (for example using a global
variable, not using a dedicated function to fetch the username) which is
probably why this is bugging me - the variable "User" doesn't seem to
the username correctly - sometimes it does, others it doesn't (even
"GET" returns "

:["oauth","cookie","default"],"authenticated":"cookie"}}"). I have spent
while now on this problem and come to the point where I need a pointer.

I don't expect you experts to teach me java script of course. It would be
great if you could point me to some couchapps I could look into to learn
this (and other stuff) is done correctly.

I looked into AndroidGrocerySync for Android. But it seems to be a native
app programmed in java.

Your help is much appreciated!


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message