useWalletAuth
Connect external wallets and complete the Sign-In With Ethereum (SIWE) authentication flow.
Request
type Request = {
hook: 'useWalletAuth',
params: [options?: WalletAuthOptions]
}
type WalletAuthOptions = OpenfortHookOptions
type OpenfortHookOptions<T = { error?: import("@openfort/react").OpenfortError }> = {
onSuccess?: (data: T) => void
onError?: (error: import("@openfort/react").OpenfortError) => void
onSettled?: (data: T | undefined | null, error: import("@openfort/react").OpenfortError | null) => void
throwOnError?: boolean
}
Response
type Response = WalletAuthReturn
type WalletAuthReturn = WalletAuthStatusFlags & {
availableWallets: AvailableWallet[]
walletConnectingTo: string | null
connectWallet(options: ConnectWalletOptions): Promise<void | { error: import("@openfort/react").OpenfortError }>
linkWallet: (options: ConnectWalletOptions) => Promise<void | { error: import("@openfort/react").OpenfortError }>
}
type WalletAuthStatusFlags = {
isLoading: boolean
isError: boolean
isSuccess: boolean
error?: import("@openfort/react").OpenfortError | null
}
type ConnectWalletOptions = {
connector: string | import("wagmi").Connector
}
type AvailableWallet = {
id: string
connector: import("wagmi").Connector
name: string
icon: import("react").ReactNode
iconShape: 'circle' | 'square' | 'squircle' | string
isInstalled?: boolean
shortName?: string
iconConnector?: import("react").ReactNode
[key: string]: unknown
}
Example
import { embeddedWalletId, useWalletAuth } from "@openfort/react"
function WalletButtons() {
const {
walletConnectingTo,
connectWallet,
linkWallet,
availableWallets,
isLoading,
isError,
isSuccess,
error,
} = useWalletAuth({
throwOnError: true,
onSuccess: () => {},
onError: () => {},
onSettled: () => {}
})
const connect = (id: string) => connectWallet({ connector: id })
const connectEmbedded = () => connectWallet({ connector: embeddedWalletId })
return null
}