[英]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:如果那仍然不起作用:您是否检查了我的建议:
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.