I have a site dashboard on GAE standard node.js environment that uses login: admin
option in handlers:
element in my app.yaml
file. This option makes google login window appear before accessing the site. Is it possible to get email and profile of user logged in?
CodePudding user response:
Updates on Feb 2
Tested on my local server
I added
login:required
in app.yaml; it's a Python3 App but I did not useusers api
; I start the app withdev_appserver.py
to make sure it uses theapp.yaml
file in the development environment; When I loaded the home page, it prompted me to sign in with[email protected]
I dumped the header output and it included the following
X-Appengine-User-Email: [email protected]
X-Appengine-User-Id: XXXXX
Original Answer
- You can use the 'users' Api and call the function
GetCurrentUser()
Example, if your code was in python, you'd have something like
from google.appengine.api import users
# Get information about the currently logged in user
users.GetCurrentUser()
# Extra - if you wanted to confirm this is an admin user
users.IsCurrentUserAdmin()
- Since you're not using Python, see if the environment variable for
USER_EMAIL
exists. The source code forusers api
has the snippet below (so see if it works for you)
email = os.environ.get('USER_EMAIL', email)
_user_id = os.environ.get('USER_ID', _user_id)