0

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?

xijdk
  • 450
  • 4
  • 8

1 Answers1

2

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 use users api; I start the app with dev_appserver.py to make sure it uses the app.yaml file in the development environment; When I loaded the home page, it prompted me to sign in with test@example.com

  • I dumped the header output and it included the following

   X-Appengine-User-Email: test@example.com
   X-Appengine-User-Id: XXXXX

Original Answer

  1. 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()
  1. Since you're not using Python, see if the environment variable for USER_EMAIL exists. The source code for users 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)

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