Files
tom goriunovandGitHub 401dc58402 Smart wallet auth (#3220)
* basic login button implementation

* refactoring and add dynamic auth button to the other pages

* connect wallet without authenticating an user

* login and logout user in blockscout account

* refactoring and RPC overrides

* authenticate user with connected wallet

* add ENS to profile button

* override evm chains and fix contract write with waas wallet

* disconnect wallet and fix docker build

* add dynamic imports to components that use web3 wallet packages

* refactor user profile directory

* clean up

* tweaks

* update pw ci script

* fix "connect wallet" button behavior

* handle linking email to profile with dynamic provider

* fix test

* async loading web3 hooks and remove dynamic loading from components that use them

* fix pw tests

* add account navigation in horizontal layout when auth provider is dynamic

* fix address verification modal

* review fixes

* spelling fixes
2026-02-18 19:42:44 +01:00

65 lines
1.8 KiB
TypeScript

import React from 'react';
import { useDisclosure } from 'toolkit/hooks/useDisclosure';
import AuthModal from '../AuthModal';
import useProfileQuery from '../useProfileQuery';
interface InjectedProps {
onClick: () => void;
}
interface Props {
children: (props: InjectedProps) => React.ReactNode;
onAuthSuccess: () => void;
ensureEmail?: boolean;
}
const AuthGuardAuth0 = ({ children, onAuthSuccess, ensureEmail }: Props) => {
const authModal = useDisclosure();
const profileQuery = useProfileQuery();
const handleClick = React.useCallback(() => {
if (profileQuery.data) {
if (ensureEmail && !profileQuery.data.email) {
authModal.onOpen();
} else {
onAuthSuccess();
}
} else {
authModal.onOpen();
}
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);
const handleModalClose = React.useCallback((isSuccess?: boolean) => {
if (isSuccess) {
if (ensureEmail && !profileQuery.data?.email) {
// If the user has logged in and has not added an email
// we need to close the modal and open it again
// so the initial screen will be correct
authModal.onClose();
window.setTimeout(() => {
authModal.onOpen();
}, 500);
return;
}
onAuthSuccess();
}
authModal.onClose();
}, [ authModal, ensureEmail, profileQuery.data, onAuthSuccess ]);
return (
<>
{ children({ onClick: handleClick }) }
{ authModal.open && (
<AuthModal
onClose={ handleModalClose }
initialScreen={ profileQuery.data && !profileQuery.data.email && ensureEmail ? { type: 'email', isAuth: true } : { type: 'select_method' } }
/>
) }
</>
);
};
export default React.memo(AuthGuardAuth0);