useWalletUiAuth
The useWalletUiAuth hook provides auth state and a signIn function for one wallet. It prefers native solana:signIn and falls back to connected-account solana:signMessage when native SIWS is unavailable.
Options
Section titled “Options”| Name | Type | Description |
|---|---|---|
wallet | UiWallet | Wallet to use for auth attempts. |
Return Value
Section titled “Return Value”| Name | Type | Description |
|---|---|---|
canSignIn | boolean | Whether this wallet can attempt auth. |
isSigningIn | boolean | Whether a sign-in request is in progress. |
messageSigningAvailable | boolean | Whether the target account supports solana:signMessage. |
nativeSignInAvailable | boolean | Whether the wallet supports solana:signIn. |
reason | WalletUiAuthUnavailableReason | undefined | Why auth is unavailable for this wallet/account. |
signIn | (options?: WalletUiAuthSignInOptions) => Promise<WalletUiAuthResult> | Starts the native or fallback auth flow for the wallet. |
Result
Section titled “Result”signIn() resolves to:
| Name | Type | Description |
|---|---|---|
account | UiWalletAccount | Account that signed in. |
input | SolanaSignInInput | SIWS input used for native SIWS or fallback message construction. |
method | 'solana:signIn' | 'solana:signMessage' | Auth method used. |
signedMessage | Uint8Array | Exact bytes signed by the wallet. |
signature | Uint8Array | Ed25519 signature returned by the wallet. |
Example
Section titled “Example”import { WalletUiAuthError, useWalletUi, useWalletUiAuth } from '@wallet-ui/react';
function AuthButton() { const { wallet } = useWalletUi();
if (!wallet) { return <button disabled>Connect wallet</button>; }
return <ConnectedAuthButton key={wallet.name} wallet={wallet} />;}
function ConnectedAuthButton({ wallet }) { const { canSignIn, isSigningIn, reason, signIn } = useWalletUiAuth({ wallet });
async function handleClick() { try { const result = await signIn({ input: { domain: window.location.host, nonce: await fetch('/api/auth/nonce').then(res => res.text()), statement: 'Sign in to Example App.', uri: window.location.origin, version: '1', }, });
await fetch('/api/auth/verify', { body: JSON.stringify({ input: result.input, method: result.method, signature: Array.from(result.signature), signedMessage: Array.from(result.signedMessage), walletAddress: result.account.address, }), headers: { 'content-type': 'application/json' }, method: 'POST', }); } catch (e) { if (e instanceof WalletUiAuthError) { console.error(e.reason); return; } throw e; } }
return ( <button disabled={!canSignIn || isSigningIn} onClick={handleClick}> {isSigningIn ? 'Signing in...' : reason ? 'Connect wallet' : 'Sign in'} </button> );}Unavailable Reasons
Section titled “Unavailable Reasons”| Reason | Meaning |
|---|---|
auth-unsupported | The wallet has neither native SIWS nor message-signing fallback. |
message-signing-unavailable | The wallet reported no output from solana:signMessage. |
missing-domain | Fallback SIWS message construction needs input.domain or location.host. |
wallet-not-connected | Fallback auth needs a connected account for this wallet. |
For wallet-list buttons that should connect before signing, use WalletUiAuth. For a complete auth flow, see the Sign In With Solana guide.