简体   繁体   English

Xumm-oauth2-pkce 在本地主机上工作,当我部署到服务器时停止

[英]Xumm-oauth2-pkce works on localhost, stops when I deploy to server

I am slowly loosing my mind on this issue, I want to do basic XUMM wallet signIn on mobile, it works perfectly in local environment, but the moment I am deploying to the server, it stops working.我在这个问题上慢慢失去了理智,我想在移动设备上进行基本的 XUMM 钱包登录,它在本地环境中完美运行,但是当我部署到服务器时,它停止工作。

Here is the code这是代码

import "./App.css";
import { XummPkce } from "xumm-oauth2-pkce";

function App() {
  const xumm = new XummPkce(my-api);

  // Xumm events start
  async function connect() {
    xumm.authorize().catch((e) => console.log("e", e));
  }

  xumm.on("error", (error) => {
    console.log("error", error);
  });

  xumm.on("success", async () => {
    const state = await xumm.state();
    console.log("success");
    console.log(state.me.account);
    // setWalletAddres(state.me.account);
  });

  xumm.on("retrieved", async () => {
    const state = await xumm.state();
    console.log("retrieved");
    console.log(state.me.account);
    // setWalletAddres(state.me.account);
  });
  //Xumm events end

  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <button onClick={connect}> Test </button>
      </header>
    </div>
  );
}

export default App;

I've noticed that when I am opening from the website, the console gives me 3 lines:我注意到当我从网站打开时,控制台给了我 3 行:

Xumm OAuth2 PKCE Authorization Code Flow lib.

Remember JWT

XummPkce attached to window

But when I open on localhost, I get 4 lines, 3 from the above, plus:但是当我在本地主机上打开时,我得到 4 行,上面的 3 行,加上:

XUMM SDK: Running in browser

Any help will be highly appreciated as I am slowly going crazy.任何帮助将不胜感激,因为我正在慢慢发疯。

Based on your message I get the idea you're testing on mobile and expecting the redirect?根据您的消息,我知道您正在移动设备上进行测试并期待重定向?

Can you please check this example: https://oauth2-pkce-demo.xumm.dev/jsmodule你能检查一下这个例子吗: https ://oauth2-pkce-demo.xumm.dev/jsmodule

The source code of that page is very clean, and works for mobile redirect and for desktop.该页面的源代码非常干净,适用于移动重定向和桌面。

The success/retrieved event handlers trigger on redirect after signing on mobile as well.在移动设备上签名后,成功/检索事件处理程序也会在重定向时触发。

Another thing to check: you mention you're running this on your server (possibly server side rendered?) .另一件要检查的事情:你提到你在你的服务器上运行它(可能是服务器端呈现?) Please make sure the Xumm SDK must run on the client side.请确保 Xumm SDK 必须在客户端运行。 If somehow a build results in for example the code trying to run on the backend instead of frontend, it won't work.如果构建以某种方式导致代码试图在后端而不是前端运行,它将无法工作。

To force the Xumm code running on the client side, you can refer to window.xumm instead of just xumm .要强制在客户端运行 Xumm 代码,您可以参考window.xumm而不仅仅是xumm


Edit (re: reply comment)编辑(回复:回复评论)

It is able to deal with a new tab, but if the tab is in a different browser, or for example you leave from an embedded browser (social media app, etc.) and then return to your stock browser it won't work.它能够处理新选项卡,但如果该选项卡位于不同的浏览器中,或者例如您离开嵌入式浏览器(社交媒体应用程序等)然后返回到您的常用浏览器,它将无法正常工作。

The PKCE flow relies on security params stored in your local/session storage. PKCE 流程依赖于存储在本地/会话存储中的安全参数。 You could try the Implicit flow, by adding this option to the constructor:您可以通过将此选项添加到构造函数来尝试隐式流程:

{ implicit: true }

(as second argument to the constructor). (作为构造函数的第二个参数)。

If that still doesn't work: did you check my suggestions:如果那仍然不起作用:您是否检查了我的建议:

  1. server side rendered (?)服务器端呈现(?)
  2. try CDN in template (head) & refer to window.xumm?在模板(head)中尝试 CDN 并参考 window.xumm?

If anybody is having the same issue, update your xumm-oauth2-pkce to 2.6.0.如果有人遇到同样的问题,请将您的 xumm-oauth2-pkce 更新到 2.6.0。 That fixed my issue.这解决了我的问题。

Another solution if you don't want to update, is to put CDN to xumm-oauth2-pkce to (head) in your index.html in public folder and listening to the xumm events in the same file.如果您不想更新,另一种解决方案是将 CDN 到 xumm-oauth2-pkce 到 (head) 在您的 index.html 中的公用文件夹中,并在同一文件中侦听 xumm 事件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript 在本地主机上工作,但在部署 github 页面或 vercel 时停止 - Javascript works on localhost, but it stops on deploy github pages or vercel 链接到另一个 html 文件在本地主机上有效,但当我将其上传到服务器时无效 - Linking to another html file works on localhost, but not when I upload it on server Favicon 可以在本地主机上运行,​​但不能在服务器上运行? - Favicon works on localhost but not on a server? 调用服务器时,ajax 调用中出现错误 500,但在 localhost 中有效 - error 500 in ajax call when call to the server, but in localhost works 当我尝试使用带有沙箱的本地主机中的 php file_get_contents() 获取 OAuth2 令牌时,Paypal Rest Api 返回 401 Unauthorized ,但在 ajax 中有效 - Paypal Rest Api returns 401 Unauthorized when i try to get OAuth2 token using php file_get_contents() in localhost with sandbox , but works in ajax jQuery自动加载脚本可在localhost上运行,但在服务器上放置时失败 - jQuery autoload script works on localhost but fails when put on a server Angular Meteor应用程序可在localhost中运行,但在部署到服务器时会失败 - Angular Meteor app works in localhost but fails when deployed to server Live Server 工作正常,但本地主机出现 404 错误 - Live Server works but I get 404 error for localhost 代码可在localhost上运行,但不能在实时服务器上运行 - code works on localhost but not live server “TypeError:无法读取未定义的属性'地址'”午餐后我在测试网中部署时收到此错误,但在本地主机中有效 - "TypeError : Cannot read property 'address' of undefined" i receive this error after lunch the deploy in the testnet, but in localhost works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM