Archived Content from Web3Auth Community
This topic was originally posted by pietro.ciattaglia on 12/5/2023.
This content has been migrated from our previous community forum to preserve valuable discussions.
I am seeking information about a specific feature on Web3Auth, similar to the ‘auto-connect’ function available on Rainbowkit. My website currently has an issue where users are logged out each time they refresh the page, requiring them to log in again.
As a temporary solution, I have implemented a useEffect hook to automatically trigger the login process upon page load.
However, this approach results in a brief popup displaying a message like ‘Connecting to…’ (I don’t recall the exact wording) every time the page is refreshed.
Although the popup closes automatically after a successful login, and the session is effectively stored, the recurring popup is a source of frustration. I’m interested in knowing if Web3Auth offers a feature to streamline this process, preventing the popup from appearing on each refresh.
useEffect(() => { try { if (web3auth.status !== 'connected') { console.log(web3auth.status); login(); } } catch (error) { setLoggedIn(false); } }, [web3auth]);
const login = async () => {
try {
console.log(‘Attempting to login…’);
const connectResponse = await web3auth.connect();
const user = await web3auth.getUserInfo();
setProvider(web3auth.provider);
const rpc = new RPC(web3auth.provider);
const address = await rpc.getAccounts();
setUser({
…user,
address: address,
});
setLoggedIn(true);
const userRef = collection(db, ‘referrals’);
const q = query(userRef, where(‘userAddress’, ‘==’, address));
const querySnapshot = await getDocs(q);
if (querySnapshot.empty) {
setShowReferralModal(true);
}
} catch (error) {
console.error(‘Login failed:’, error);
}
};