I'm trying to create a Google Sheets add-on that runs in a sidebar. This is my first and I'm having a hard time working through the Auth modes.
This is the doc I'm using to reference.
When someone in my org installs the script, they see the menu title, but the add-on fails to load the menu items. The logging shows that Exception: You do not have permission to call getScriptProperties at ...
. This is from a library that I wrote and am referencing in my script. When they use it on a doc where I've used it before, they're able to see the menu items.
Based on this chart, it looks like that user is in AuthMode.NONE since they cannot access Properties.
This is the code that I have at the top of my file.
function onInstall(e) {
onOpen(e);
}
function onOpen(e) {
console.info('onOpen(e) fired')
var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp or FormApp.
if (e && e.authMode == ScriptApp.AuthMode.NONE) {
console.info("(e && e.authMode == ScriptApp.AuthMode.NONE)")
// Add a normal menu item (works in all authorization modes).
menu.addItem("Show Sidebar", "showSidebar");
menu.addToUi();
} else {
// Add a new menu (doesn't work in AuthMode.NONE).
log("not (e && e.authMode == ScriptApp.AuthMode.NONE)")
var topUI = SpreadsheetApp.getUi();
topUI.createMenu("Test Set Creator")
.addItem("Show Sidebar", "showSidebar")
.addToUi();
}
console.info(`The user is ${e.user}`)
console.info(`The user's auth mode is ${e.authMode}`)
console.info(`The source is ${e.source}`)
}
So essentially, I want a user to install the add-on and then be able to use it on any spreadsheet they want in the org's domain, not just where it's been used before. I'm having a hard time wrapping my mind around how the different Auth Modes work and how they change per user/per sheet. If the user has to authorize the add on when they install it, why wouldn't they have access to the add on in a new spreadsheet they open?
Here are some other resources I've tried to use: Google Doc onOpen will not fire when spreadsheet is accessed