Cannot Log In in Production — 'LoginError: login popup has been closed by the user,'

Hi, I am building an application in React and want to use Web3Auth to login with emails or social media.

Everything works well in my React development environment, but as soon as I build the app and move it to Django — production — I start getting these errors:

image

This happens as soon as the pop-up ‘Sing in - Google Accounts’ appears (or any of the others— Discord, Twitter, etc.)

I read a similar topic, which suggested hard reload and clearing browsing data. Didn’t help.
I tried other browsers. Nothing.
I tried my phone. Fails also.

Any suggestions here?—Can anyone help?
Kindly
Vajra

hi @brilliantportal,

I hope you are doing great. Can you tell me more about what you mean by “I build the app and move it to Django”?

Also Can you share with us the package versions and some code snippets so we can see what is going on?

Of course, you can control these errors by using the structure → try … catch {}

Hi, thanks for answering.

Yeah, simply that I build the app in React, where everything works, and I use Django as my backend in production. When I move it there, to production, Web3Auth no longer works.

Package versions:
“web3auth/base”: “^8.6.1”,
“web3auth/ethereum-provider”: “^8.6.1”,
“web3auth/modal”: “^8.6.1”,
(some more)
“devDependencies”: {
“esbuild-plugins/node-globals-polyfill”: “^0.2.3”,
“rollup/plugin-replace”: “^5.0.5”,
“types/react”: “^18.3.3”,
“vitejs/plugin-react”: “^4.2.1”,
“eslint”: “^8.57.0”,
“eslint-plugin-react”: “^7.34.1”,
“eslint-plugin-react-hooks”: “^4.6.0”,
“eslint-plugin-react-refresh”: “^0.4.6”,
“vite”: “^5.2.0”

[of course, in my code there are @ before the packages—excluding here because “mentioning users error”]

Code snippets
is TSX

import React, { useEffect, useState } from “react”;
import { Web3Auth } from “web3auth/modal”;
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from “web3auth/base”;
import { EthereumPrivateKeyProvider } from “web3auth/ethereum-provider”;
import Button from ‘-@mui/material/Button’;
import “./ConnectWeb3Auth.css”;

const clientId = “xxx”;

const chainConfig = {
chainId: “0x1”, // 0x1 for Mainnet
rpcTarget: “https://rpc.ankr.com/eth”,
chainNamespace: CHAIN_NAMESPACES.EIP155,
displayName: “Ethereum Mainnet”,
blockExplorerUrl: “https://etherscan.io/”,
ticker: “ETH”,
tickerName: “Ethereum”,
logo: “Bitmap”,
};

const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig: chainConfig },
});

const web3auth = new Web3Auth({
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider: privateKeyProvider,
});

const Web3AuthComponent = ({ onLogin, onLogout }) => {
const [provider, setProvider] = useState(null);
const [loggedIn, setLoggedIn] = useState(false);

useEffect(() => {
const init = async () => {
try {
if (!web3auth.provider) {
await web3auth.initModal();
setProvider(web3auth.provider);

      if (web3auth.connected) {
        const accounts = await web3auth.provider.request({ method: 'eth_accounts' });
        setLoggedIn(true);
        onLogin(accounts[0], disconnect); // Pass the account address and disconnect function to the parent component
      }
    }
  } catch (error) {
    console.error(error);
  }
};

init();

}, []);

const login = async () => {
const web3authProvider = await web3auth.connect();
setProvider(web3authProvider);
if (web3auth.connected) {
const accounts = await web3auth.provider.request({ method: ‘eth_accounts’ });
setLoggedIn(true);
onLogin(accounts[0], disconnect); // Pass the account address and disconnect function to the parent component
}
};

const logout = async () => {
try {
await web3auth.logout();
setProvider(null);
setLoggedIn(false);
onLogout(); // Call onLogout when logged out
} catch (error) {
console.error(“Error logging out:”, error);
}
};

const disconnect = async () => {
try {
await web3auth.logout();
localStorage.clear(); // Clear local storage to forget session completely
setProvider(null);
setLoggedIn(false);
onLogout(); // Call onLogout when logged out
} catch (error) {
console.error(“Error disconnecting:”, error);
}
};

return (


{loggedIn ? (
<Button
variant=“contained”
onClick={logout}
sx={{
borderRadius: 2,
backgroundColor: ‘#7ec6fa’,
‘&:hover’: {
backgroundColor: ‘#646cffaa’,
},
}}
>
Logout

) : (
<Button
variant=“contained”
onClick={login}
sx={{
borderRadius: 2,
backgroundColor: ‘#7ec6fa’,
‘&:hover’: {
backgroundColor: ‘#646cffaa’,
},
}}
>
Connect Email

)}
{loggedIn && (
<Button
variant=“contained”
onClick={disconnect}
sx={{
borderRadius: 2,
backgroundColor: ‘#ff6666’,
‘&:hover’: {
backgroundColor: ‘#cc0000’,
},
marginLeft: 2,
}}
>
Disconnect Account

)}

);
};

export default Web3AuthComponent;

Thank you, good idea :slight_smile:,
Grateful for any insights,
Sending my very best!

bump
anyone, please? @TomTom

hi @brilliantportal

Did you try any of our examples over Django?

I think It would be ok to discard any problem with Django.

Yeah! Your example works with Django. So it’s a problem with how I set it up in React…
Thanks!
I’ll look into it—helpful man :pray:

2 Likes

Very strange.

When I run the pure example in Django, it works.

When I copy the code into my React Project and build it and run it then in Django, I get the errors I got above.

All I actually do is download this — web3auth-pnp-examples/web-modal-sdk/blockchain-connection-examples/evm-modal-example at main · Web3Auth/web3auth-pnp-examples · GitHub — install it, copy the App.tsx into my project, and then call it in my application like this:

<ConnectWeb3Auth onLogin={(account, disconnect) => handleLogin(account, 'web3auth', disconnect)} onLogout={handleLogout} />

Like I said, works in React dev, not after build.

Am I missing something? Do I need something more in my app apart from the ‘App.tsx’? The ‘config-overrides.js’ or something?

Thanks for your patience :raised_hand_with_fingers_splayed:

I found a way to make it work—by changing the Cross-Origins like this:

['Cross-Origin-Opener-Policy'] = 'unsafe-none'
['Cross-Origin-Embedder-Policy'] = 'unsafe-none'

So it works, but—as it itself is actually saying, lol—it’s unsafe.

So with these settings, the Web3Auth login goes through, with this in the console:

Cross-Origin-Opener-Policy policy would block the window.closed call.

Annoying. Don’t know. If anyone sees this and knows what’s going on—please say!

Solved this problem.
My sloppiness.
Thanks all
:raised_hand_with_fingers_splayed:

1 Like

One more thing here, actually.

Do we have a simple way of disabling the ‘whitelabel’ and ‘MFA’ settings in this setup?:

Just from playing with it for a while, it seems that even when I remove all the mentions of these two from the code, I still get:

and cannot get it running on the Base Plan.

Cheers,
BP

hi BP,

can you share with me the code that you are using ?

Also you can read our docs about whitelabel → https://web3auth.io/docs/sdk/pnp/web/modal/whitelabel and MFA → Multi Factor Authentication with PnP Web Modal SDK | Documentation | Web3Auth

Hi,
literally just this code:

github.com

Contribute to Web3Auth/web3auth-pnp-examples development by creating an account on GitHub.

When I put my Base Plan Client ID, I get the error above.
Ok, thanks for the links! Might find something there!
Good day!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.