Skip to content

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.

NameTypeDescription
walletUiWalletWallet to use for auth attempts.
NameTypeDescription
canSignInbooleanWhether this wallet can attempt auth.
isSigningInbooleanWhether a sign-in request is in progress.
messageSigningAvailablebooleanWhether the target account supports solana:signMessage.
nativeSignInAvailablebooleanWhether the wallet supports solana:signIn.
reasonWalletUiAuthUnavailableReason | undefinedWhy auth is unavailable for this wallet/account.
signIn(options?: WalletUiAuthSignInOptions) => Promise<WalletUiAuthResult>Starts the native or fallback auth flow for the wallet.

signIn() resolves to:

NameTypeDescription
accountUiWalletAccountAccount that signed in.
inputSolanaSignInInputSIWS input used for native SIWS or fallback message construction.
method'solana:signIn' | 'solana:signMessage'Auth method used.
signedMessageUint8ArrayExact bytes signed by the wallet.
signatureUint8ArrayEd25519 signature returned by the wallet.
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>
);
}
ReasonMeaning
auth-unsupportedThe wallet has neither native SIWS nor message-signing fallback.
message-signing-unavailableThe wallet reported no output from solana:signMessage.
missing-domainFallback SIWS message construction needs input.domain or location.host.
wallet-not-connectedFallback 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.