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?
Asked
Active
Viewed 162 times
0
xijdk
- 450
- 4
- 8
1 Answers
2
Updates on Feb 2
Tested on my local server
I added
login:requiredin app.yaml; it's a Python3 App but I did not useusers api; I start the app withdev_appserver.pyto make sure it uses theapp.yamlfile in the development environment; When I loaded the home page, it prompted me to sign in withtest@example.comI dumped the header output and it included the following
X-Appengine-User-Email: test@example.com
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_EMAILexists. The source code forusers apihas 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)
NoCommandLine
- 5,044
- 2
- 4
- 15
-
Thanks for your answer, but I'm using node.js instead of python. Is there a node.js version of google.appengine.api? – xijdk Jan 31 '22 at 17:29