I am trying to get the current user object in a Google App Engine app however it seems to be returning nothing.
I used the example code at https://github.com/takatama/gae-webapp2-auth/blob/master/handlers.py to write the user handler.
My app logs in succesfully, however get_current_user() is returning NoneType. Is it this function call is in an AJAX POST and the session is not initialised? Do I have to add a decorator somewhere?
The function
get_current_userreturnsNoneif the user is not currently logged in. One normal way to handle this is to first calluser = users.get_current_user()and then use anifblock to determine if they are logged in (this example taken from the docs):If
get_current_user()returnsNone, we know that the user is not logged in, so we useusers.create_login_url()to create a link that will allow the user to authenticate, after whichget_current_user()will return theUserobject for that user (did I say ‘user’ enough? 🙂 ).