0

I am creating a web app using Google Apps Script, and have run into kind of a wall.

Sometimes the users using the web app use it while being logged in with multiple Google accounts. There is a known error that shows up when a user attempts to access a Google web app while being logged in with multiple accounts: Can't log in to Google Apps Scripts

The known solutions are:

  1. Log out of all accounts and log in as just one.
  2. Use incognito mode, thus being logged in as just one user
  3. Use a separate browser for separate Google Accounts.

Unfortunately, none of these solutions are fitting for the current situation. I myself know how to deal with the error, but how do I programmatically inform the user of these solutions?

What I am trying to do is to intercept this error page, and put out my own error, that could instruct the user to log out of their other accounts. I am deploying the web app using Google Sites, but have not had any luck with it there.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • Please add more details i.e. the web app deployment settings, if your proxy is set to use V8 or Rhino. It might also be helpful that you include a [mcve]. – Rubén Mar 27 '21 at 23:33
  • Also mention if you are using Google Workspace account or a common Google account (also called consumer account) – Rubén Mar 27 '21 at 23:39

3 Answers3

2

Check the Issue Tracker

Unexpected "authorization is required" error from google.script.run after installing Sheets add-on while logged into multiple gmail.com accounts

You haven't mentioned what you are trying to accomplish, but there may be a workaround there.

Another idea might be to make an intermediate page that will serve as a sort of "landing page" that can remind your users about this issue and then re-direct them to the Web App. If you use cookies or the local storage API, then you could have it redirect immediately if they have seen it within the last few days.

Current known status of the bug

I seem to remember seeing somewhere, though I can't find it now, that the Apps Script team were planning on starting work to fix this in 2021.

Rubén
  • 34,714
  • 9
  • 70
  • 166
iansedano
  • 6,169
  • 2
  • 12
  • 24
  • Thank you for your answer! Unfortunately, I am not building an add-on so these two solutions will not work for me. But I may just have to go ahead and use the "Landing Page" idea. – MuteThunder Mar 25 '21 at 23:06
1

As a workaround, you can start with a fresh browser session, log into the account that is intended to run the script FIRST, load the script at least once with the intended account, and only then sign into the secondary account.

To describe my specific use case:

  • Google account A: allows for script execution
  • Google account B: blocks script execution as a domain policy

If one signs first into account B, attempts to authorize the script, and then signs into account A to attempt to run it from the latter, even though they're explicitly attempting to execute the script with account A, the script fails silently. It's worth mentioning that the script in question relies on HtmlService. This doesn't affect other scripts within the project which don't rely on said service.

The steps for this work-around are:

  1. Start from a fresh session
  2. Sign into account A
  3. Authorize & run the script in full
  4. Sign into account B
  5. Run the script again from account A
  6. Avoid attempting to authorize the script from account B

Then the script does execute, even after multiple refreshes. Closing and re-opening the spreadsheet the script is bound to won't interrupt it either.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • I respectfully beg to differ @StephenOstermiller . My answer solves the underlying issue, making it unnecessary for the original poster to even develop a solution for "intercepting the error page" -- since there'll be no error. Moreover, if my answer is being deleted, by the same rationale you should delete the one below by Pritesh Patel too. – Pedro Ribeiro May 08 '23 at 13:28
  • 1
    OK, I can see that. I edited your answer to focus on your work-around rather than "I'm having this problem too," to make it clearer that it answers the question. – Stephen Ostermiller May 08 '23 at 14:43
0

I finally figured out how to get around this. I have a similar situation. I'm logged in to multiple Google accounts all the time. I usually have to open an incognito windows.

But, what I have learned is, first log out of all accounts. Then log in to the account which is required for the Google Web App script. Let the Web app load.

Then, log in to your other accounts. Once you have logged in with the account that is required to authenticate the Google Web app, then logging into other Google accounts won't interfere.

I haven't found this solution anywhere else.