错误(状态为 500)和带有 google apps 脚本重定向功能的 X-Frame-Options

问题描述 投票:0回答:1

我目前正在尝试使用 google apps 脚本构建一个网络应用程序,并且我已经实现了登录功能。 登录按预期进行,但随后我尝试将用户重定向到我的 Web 应用程序的仪表板。仪表板的当前代码是应用程序脚本中带有 h1 标题的新 HTML 文件的基本代码,因此没有任何问题。

在我的login.html 文件中,这就是将用户重定向到仪表板页面的方式:

function onLoginSuccess(sessionId) {
      if (sessionId) {
        console.log('Success')
        console.log(sessionId)
        window.location.href = "dashboard?sessionId=" + sessionId;
        console.log('Success')
      } else {
        alert("Invalid email or password. Please try again.");
      }
    }

我尝试使用

"dashboard.html?sessionId=" +sessionId
的网址,但在 F12 控制台中收到以下错误:
Failed to load resource: the server responded with a status of 500 ()
然后我尝试了一个没有 html 的 url
"dashboard?sessionId=" +sessionId
,现在出现以下错误:
Refused to display 'https://developers.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
然后我尝试在返回 HtmlService 行中添加
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
,但我仍然收到错误。

使用这两个 URL,成功和会话 ID 都会被调用到控制台中。

有办法解决这个问题吗?也许是另一种重定向用户的方法,或者只是修复错误的方法?

javascript html google-apps-script
1个回答
0
投票

找到了一种轻松重定向的方法:

function getScriptURL() {
  return ScriptApp.getService().getUrl();
}

然后,我在需要时调用该函数,它会为我提供应用程序 URL,只需在其旁边添加重定向即可。

© www.soinside.com 2019 - 2024. All rights reserved.