Archived Content from Web3Auth Community
This topic was originally posted by githubdiscussions on 2/27/2023.
This content has been migrated from our previous community forum to preserve valuable discussions.
I tried logging in through "uxmode: redirect". And I'm trying to call the API through "ADAPTER_EVENTS.CONNECTED" value of reconnected. However, in this mode, the value of reconnected always comes to "true", even though it is initial. Is there an appropriate section to put the login API through a different lifecycle?
(In the "uxmode: popup", it returned "false" the first time.)
using @web3auth/core
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="useEffect(() => { const subscribeAuthEvents = (web3auth: Web3AuthCore) => { web3auth.on(ADAPTER_EVENTS.CONNECTED, async (data: IWeb3AuthData) => { console.log('Yeah!, you are successfully logged in', data); setUser(data); setWalletProvider(web3auth.provider!); <pre><code> if (!data.reconnected) { // LOGIN API REQUEST area [if success. get Accesstoken] } });async function init() {
try {
setIsLoading(true);
const web3AuthInstance = new Web3AuthCore({
chainConfig: CHAIN_CONFIG[CHAIN_ENV],
clientId,
web3AuthNetwork: CHAIN_ENV,
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
clientId,
network: CHAIN_ENV,
uxMode: 'redirect',
},
});
web3AuthInstance.configureAdapter(openloginAdapter);
subscribeAuthEvents(web3AuthInstance);
setWeb3Auth(web3AuthInstance);
await web3AuthInstance.init();
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
}
init();
}, [setWalletProvider]);"><pre class=“notranslate”><code class=“notranslate”>useEffect(() => {
const subscribeAuthEvents = (web3auth: Web3AuthCore) => {
web3auth.on(ADAPTER_EVENTS.CONNECTED, async (data: IWeb3AuthData) => {
console.log(‘Yeah!, you are successfully logged in’, data);
setUser(data);
setWalletProvider(web3auth.provider!);
if (!data.reconnected) {
// LOGIN API REQUEST area [if success. get Accesstoken]
}
});
async function init() {
try {
setIsLoading(true);
const web3AuthInstance = new Web3AuthCore({
chainConfig: CHAIN_CONFIG[CHAIN_ENV],
clientId,
web3AuthNetwork: CHAIN_ENV,
});
const openloginAdapter = new OpenloginAdapter({
adapterSettings: {
clientId,
network: CHAIN_ENV,
uxMode: 'redirect',
},
});
web3AuthInstance.configureAdapter(openloginAdapter);
subscribeAuthEvents(web3AuthInstance);
setWeb3Auth(web3AuthInstance);
await web3AuthInstance.init();
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
}
init();
}, [setWalletProvider]);
</code></pre>
<p></code></pre></div><br/> <br /> Originally posted by: <a href=‘blockodyssey-bjkim (김병준) · GitHub’>blockodyssey-bjkim</a><br/> <br /> Check the discussion at: <a href=‘The reconnected value of "ADAPTER_EVENTS.CONNECTED" always comes out as "true". · Web3Auth · Discussion #1382 · GitHub’>https://github.com/orgs/Web3Auth/discussions/1382</a></p>