useEnsAuth
A React hook for checking ENS-based authentication status and getting connected ENS information.
Usage
import { useEnsAuth } from '@justaname.id/react'
function EnsAuthComponent() {
const {
isLoggedIn,
connectedEns,
isEnsAuthPending,
isEnsAuthFetching,
isEnsAuthLoading,
refreshEnsAuth
} = useEnsAuth({
backendUrl: 'https://api.justaname.id',
currentEnsRoute: '/auth/current-ens',
enabled: true,
local: false
})
if (isEnsAuthLoading) return <div>Checking authentication...</div>
return (
<div>
{isLoggedIn && connectedEns ? (
<div>
<p>Welcome, {connectedEns.ens}!</p>
<p>Address: {connectedEns.address}</p>
<p>Chain ID: {connectedEns.chainId}</p>
<button onClick={refreshEnsAuth}>Refresh Auth</button>
</div>
) : (
<div>
<p>Not authenticated</p>
<button onClick={refreshEnsAuth}>Check Auth Status</button>
</div>
)}
</div>
)
}
Returns
UseEnsAuthReturn
<T
> - An object containing:
isLoggedIn
: Boolean indicating if user is authenticatedconnectedEns
: ENS authentication data object or null/undefinedisEnsAuthPending
: Boolean indicating if the auth check is pendingisEnsAuthFetching
: Boolean indicating if the auth check is fetchingisEnsAuthLoading
: Boolean indicating if the auth check is loadingrefreshEnsAuth
: Function to manually refresh the authentication status
Parameters
params?:
UseEnsAuthParams
- Optional parameters includingbackendUrl
,currentEnsRoute
,enabled
,local
Type Parameters
T extends
object
=object
- Custom user type extending object
Defined in
packages/@justaname.id/react/src/lib/hooks/signIn/useEnsAuth.ts:33
Last updated
Was this helpful?