I have a Google Web App for a school that has a domain for G Suite, i.e. emails are @theschool.org. The app is connected to a spreadsheet that includes a whitelist of email addresses (teachers at the school) that are allowed to access the app. All others get an "access denied" message when the page loads. The script uses Session.getEffectiveUser().getEmail()
to get the user's email and compare it to the list.
Some users use personal devices or chromebooks where they are signed in to both their personal gmail account and the school's domain account. Some experimentation has revealed that in this situation, Session.getEffectiveUser().getEmail()
and Session.getActiveUser().getEmail()
always return the email address for the account that was signed in first, which means users are being denied access even though they've signed in (later) with their whitelisted account. Curerently, they have to sign out all accounts, then sign in the school account to gain access.
I would like to get a list of all gmail addresses the user is currently signed in with, so I can check whether any of them is on the whitelist, avoiding the need to sign out and back in. Is there a way to do this within Apps Script?
Google's documentation on the User class and the Session class does not mention anything about multiple accounts.