How to share an access with Authorized users in Apps Script Web App without them giving access to Google Sheets?

How to give permission to Authorized users to use the apps script web app without them giving access the google sheets? I am so confused right now. Please help me…
So I also create AuthorizedUsers sheet where there is the list of the emails of the authorized people I want to give access. So when they click the link of the web app the authorized users should be redirected to the index page while the non authorized users should get the message “You are not authorized to access this application.” but the issue here is that, when the other users tried to access the web app even if their email is in the AuthorizedUsers sheet they are still getting a message like this “You are not authorized to access this application.”

This is the code I tried.
In the manage deployments I’ve set the following:
Execute as:
Me (my email)

Who has access:
Anyone with Google account

Code.gs

function doGet(e) {
  // Check if the event object e is defined and has parameter
  var page = (e && e.parameter) ? e.parameter.page || 'index' : 'index'; // Default to 'index' if no page is specified or e is undefined

  var userEmail = Session.getActiveUser().getEmail();
  Logger.log("User Email from Session: " + userEmail); // Debugging line

  if (isAuthorized(userEmail)) {
    logUserEmail(userEmail);
    return HtmlService.createTemplateFromFile(page).evaluate();
  } else {
    // Redirect to an unauthorized access page or show an error message
    return HtmlService.createHtmlOutput("You are not authorized to access this application.");
  }
}

function loadIndex(e) {
  // Check if the event object e is defined and has parameter
  var page = (e && e.parameter) ? e.parameter.page || 'index' : 'index'; // Default to 'index' if no page is specified or e is undefined

  var userEmail = Session.getActiveUser().getEmail();
  Logger.log("User Email from Session: " + userEmail); // Debugging line

  if (isAuthorized(userEmail)) {
    logUserEmail(userEmail);
    return HtmlService.createTemplateFromFile(page).evaluate();
  } else {
    // Redirect to an unauthorized access page or show an error message
    return HtmlService.createHtmlOutput("You are not authorized to access this application.");
  }
}

function logUserEmail(email) {
  var email = Session.getActiveUser().getEmail();
  Logger.log("User Email: " + email);
}

function isAuthorized(email) {
  var sheet = SpreadsheetApp.openById('13dStidKhr3EcvDUZTZWxFVc5N2rQkfbGySclp0JqNTI').getSheetByName('AuthorizedUsers');
  var data = sheet.getRange('A:A').getValues(); // Get all email addresses in column A
  var emails = data.flat().filter(String); // Flatten and remove empty values

  Logger.log("Authorized Emails: " + JSON.stringify(emails)); // Debugging line
  return emails.includes(email);
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

New contributor

Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật