Firebase authentication provides a free, multi-platform sign-in system that could help make sure that the workflows which require some form of user identification (especially, pertaining to google sign-in) get a lot more simpler to configure and consume within the google apps script realm.
Disclaimer: This post makes public use of firebase config object; if you're uncomfortable doing so, please proceed with caution. if it helps, firebase's official demo app too does the same as they define this config object as "...non-secret identifiers for your Firebase project..."
Problem statement
In case you already didn't know about this, there's an existing issue while accessing Apps Script based Web Apps from a "logged-in" user's point of view on the following fronts -
the Web App behaves differently when logged in from more than a single account on your browser
the Apps Script function responsible to detect the active or current user behaves differently when it comes to g suite and non-G Suite (i.e. Gmail) users
Demo
Here's a quick preview of the user details that can be captured using Google sign-in via Firebase's pre-built UI for web authentication -
Codebase
You can access the entire script on my GitHub repository here and here's the snapshots for reference -
a Google Cloud & Firebase accounts - these are 2 separate entities and you can sign-up for their respective free tiers
Setup
Firebase account
you'd first need to setup your Firebase project in order to add the required details in your javascript project
make a note of the config object as you'd need that while configuring the Index.html file of your Apps Script Web App
setup sign-in methods via Firebase's console: authnetication > Sign-in methods
for the purposes of this post, I've only enabled Google; however, you're free to experiment with the rest on your own accord
on the same page as point # 2, when you scroll down a bit to the 'authorised domains' segment, you'd get to see a few domains already registered; do not delete any of those and proceed to add the following -
googleusercontent.com
That's all you'd need to do on the firebase side of things.
Google Apps Script
to begin with, copy the exact code along with the file structure as shared in the codebase above.
replacce the items from under the firebaseConfig variable with the details you captured by completing step 1 of the previous phase
deploy the script as a web app which is accessible by anyone, even anonymous
this should complete the setup!
Gotchas
the front-end of the web app may seem a bit glitchy i.e. even after signing-in, you may see the sign-in button but just refresh the page and that should disappear; the same goes for the sign-out button
I did try configuring phone & email verification but gave up as soon as i hit the first error on those 😅 it should be easy enough to configure though; will continue updating this post as and when I have better solutions