Session & Auth
Hooks for session state, authentication, address access, logout, key recovery, and linked profiles.
EmbarkAI provides several hooks for working with session data. For most applications, useAccountSession is the recommended starting point.
Import
import {
useAccountSession,
useSession,
useLoadingStatus,
useAddress,
useLogout,
useHydrated,
} from '@embarkai/ui-kit'useAccountSession
Returns the current session object when a user is authenticated, or null when disconnected. This is the recommended hook for checking authentication state.
import { useAccountSession } from '@embarkai/ui-kit'
function Dashboard() {
const session = useAccountSession()
if (!session) {
return <p>Please connect your wallet.</p>
}
return <p>Welcome back! Session active.</p>
}useSession
A lower-level hook that gives direct access to the session store via a selector function. Use this when you need fine-grained control over which store values trigger re-renders.
import { useSession } from '@embarkai/ui-kit'
function AddressDisplay() {
const address = useSession((state) => state.address)
return <span>{address ?? 'Not connected'}</span>
}useAddress
Returns the connected smart wallet address directly:
import { useAddress } from '@embarkai/ui-kit'
function WalletAddress() {
const address = useAddress()
return <code>{address}</code>
}useLoadingStatus
Returns the session loading state, useful for displaying spinners or skeleton screens during authentication.
import { useLoadingStatus } from '@embarkai/ui-kit'
function AppLoader() {
const { isSessionLoading, sessionStatus } = useLoadingStatus()
if (isSessionLoading) {
return <div className="spinner">Loading ({sessionStatus})...</div>
}
return <main>App ready</main>
}| Property | Type | Description |
|---|---|---|
isSessionLoading | boolean | true while the session is being established or restored. |
sessionStatus | string | Current status label (e.g., 'hydrating', 'connecting', 'ready'). |
useLogout
Returns a logout function that ends the current session and clears stored credentials.
import { useLogout } from '@embarkai/ui-kit'
function LogoutButton() {
const { logout } = useLogout()
return <button onClick={logout}>Disconnect</button>
}useHydrated
Returns true once the SDK has finished restoring a previous session from localStorage. Before hydration completes, session hooks may return null even if the user was previously connected.
import { useHydrated, useAccountSession } from '@embarkai/ui-kit'
function ProtectedRoute({ children }: { children: React.ReactNode }) {
const hydrated = useHydrated()
const session = useAccountSession()
if (!hydrated) return <p>Restoring session...</p>
if (!session) return <p>Please connect to continue.</p>
return <>{children}</>
}useRecoveryUserId
Returns the user ID used for MPC key recovery. This is set during initial wallet creation and is required when restoring keys on a new device.
import { useRecoveryUserId } from '@embarkai/ui-kit'
function RecoveryInfo() {
const recoveryUserId = useRecoveryUserId()
if (!recoveryUserId) return null
return <p>Recovery ID: {recoveryUserId}</p>
}useHasServerVault
Returns whether the current user has a server-side key vault (ShareVault backup). When true, the user can recover their wallet without the original device.
import { useHasServerVault } from '@embarkai/ui-kit'
function VaultStatus() {
const hasVault = useHasServerVault()
return (
<p>
Key backup: {hasVault ? 'Enabled ✓' : 'Not configured'}
</p>
)
}useLinkedProfiles
Returns the list of social and email profiles linked to the current account (e.g., Google, GitHub, email).
import { useLinkedProfiles } from '@embarkai/ui-kit'
function LinkedAccounts() {
const profiles = useLinkedProfiles()
if (!profiles?.length) return <p>No linked accounts.</p>
return (
<ul>
{profiles.map((profile) => (
<li key={profile.id}>
{profile.provider}: {profile.identifier}
</li>
))}
</ul>
)
}Return Value
Each profile object contains:
| Property | Type | Description |
|---|---|---|
id | string | Unique profile identifier. |
provider | string | Provider name (e.g., 'google', 'github', 'email'). |
identifier | string | Email address or username. |
Session Lifecycle
The session moves through these stages after the Provider mounts:
- Hydrating — SDK checks localStorage for a stored session.
- Connecting — User initiates authentication (passkey, email, social, or external wallet).
- Establishing — MPC key generation or key recovery is in progress.
- Ready — Session is active, all hooks return live data.
- Disconnected — User logs out or the session expires.
Use useLoadingStatus to track these transitions and useHydrated to know when step 1 is complete.
Full Example
import {
useAccountSession,
useAddress,
useLoadingStatus,
useLogout,
useHydrated,
} from '@embarkai/ui-kit'
function UserProfile() {
const hydrated = useHydrated()
const session = useAccountSession()
const address = useAddress()
const { isSessionLoading } = useLoadingStatus()
const { logout } = useLogout()
if (!hydrated || isSessionLoading) return <p>Loading...</p>
if (!session) return <p>Not connected</p>
return (
<div>
<p>Wallet: {address}</p>
<button onClick={logout}>Sign Out</button>
</div>
)
}Next Steps
- useBalance — read wallet balances
- useSendTransaction — send transactions from the connected wallet
- Connect Wallet — the button component that triggers authentication