Please provide the following details too when asking for help in this category:
-
SDK Version: 6.1.7
-
Platform: React
-
Browser Console Screenshots:
-
Related to Custom Authentication? Please provide the following info too: (Optional)
- Verifier Name:
- JWKS Endpoint:
- Sample idToken(JWT)
Please provide the Web3Auth initialization and login code snippet below:
useEffect(() => {
const init = async () => {
try {
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: process.env.REACT_APP_CHAIN_ID as string,
rpcTarget:
process.env.REACT_APP_PROVIDER_URL ?? “https://rpc.ankr.com/eth”,
displayName: “Ethereum Mainnet”,
blockExplorer: “https://goerli.etherscan.io”,
ticker: “ETH”,
tickerName: “Ethereum”,
};
const web3auth = new Web3AuthNoModal({
clientId: process.env.REACT_APP_CLIENT_ID as string,
chainConfig,
web3AuthNetwork:
(process.env.REACT_APP_NETWORK as OPENLOGIN_NETWORK_TYPE) ?? “cyan”,
});
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig },
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
whiteLabel: {
name: "W3A Heroes",
url: "https://web3auth.io",
logoLight: "https://web3auth.io/images/w3a-L-Favicon-1.svg",
logoDark: "https://web3auth.io/images/w3a-D-Favicon-1.svg",
defaultLanguage: "en", // en, de, ja, ko, zh, es, fr, pt, nl
dark: false, // whether to enable dark mode. defaultValue: false
theme: {
primary: "#00D1B2",
},
},
mfaSettings: {
deviceShareFactor: {
enable: true,
priority: 1,
mandatory: true,
},
backUpShareFactor: {
enable: true,
priority: 2,
mandatory: false,
},
socialBackupFactor: {
enable: true,
priority: 3,
mandatory: false,
},
passwordFactor: {
enable: true,
priority: 4,
mandatory: false,
},
},
},
loginSettings: {
mfaLevel: "optional",
},
privateKeyProvider,
});
web3auth.configureAdapter(openloginAdapter);
setWeb3auth(web3auth);
await web3auth.init();
setProvider(web3auth.provider);
console.log("web3auth.connected", web3auth.connected);
if (web3auth.connected) {
await logout();
// window.location.reload();
}
} catch (error) {
console.error(error);
}
};
init();
}, []);
const loginWithEmail = async () => {
try {
if (!web3auth) {
uiConsole(“web3auth not initialized yet”);
return false;
}
console.log(“Here…”);
if (WALLET_ADAPTERS) {
const web3authProvider = await web3auth.connectTo(
WALLET_ADAPTERS.OPENLOGIN,
{
loginProvider: “email_passwordless”,
extraLoginOptions: {
login_hint: email,
},
}
);
console.log(“Here222…”, email);
console.log(“web3 auth”, web3authProvider);
setProvider(web3authProvider);
if (web3authProvider)
try {
let address = await getAccountsByEther(web3auth?.provider);
setKeyInfo({ publicKey: address, privateKey: “” });
} catch (error) {
await logout();
return false;
}
await getUserInfo();
setLoggedIn(true);
return true;
}
} catch (Err) {
console.log(“err”, Err);
toast.error(
“Wallet is not ready yet, Please try after sometime or try refreshing page”
);
await logout();
return false;
}
};