# `useWalletAuth`

Authenticates users with external wallets using Sign-In with Ethereum (SIWE). Supports MetaMask, WalletConnect, and other Ethereum wallets.

## Usage

```tsx
import { useWalletAuth } from '@openfort/react-native';

function SiweLogin({ walletAddress }: { walletAddress: string }) {
  const { generateSiweMessage, signInWithSiwe, isAwaitingSignature } = useWalletAuth({
    onSuccess: ({ user }) => console.log('SIWE authentication successful:', user?.id),
  });

  const login = async () => {
    // Step 1: Generate SIWE message
    const { message } = await generateSiweMessage({
      wallet: walletAddress,
      from: { domain: 'example.com', uri: 'https://example.com' },
    });
    if (!message) return;

    // Step 2: Request signature from user's wallet
    const signature = await signMessageWithWallet(message); // Your wallet signing logic

    // Step 3: Authenticate with signed message
    await signInWithSiwe({ walletAddress, signature, messageOverride: message });
  };

  return null;
}
```

## Hook options

Pass these options when initializing the hook:

```ts
type WalletHookOptions = {
  onSuccess?: (data: WalletAuthResult | GenerateSiweMessageResult) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```

## Return type

The hook returns the following:

```ts
type UseWalletAuthReturn = {
  generateSiweMessage(options: GenerateSiweOptions): Promise<GenerateSiweMessageResult>
  signInWithSiwe(options: SiweSignInOptions): Promise<WalletAuthResult>
  linkSiwe(options: LinkSiweOptions): Promise<WalletAuthResult>
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  isAwaitingSignature: boolean
  isGeneratingMessage: boolean
  isSubmittingSignature: boolean
  error: Error | null
}

type WalletAuthResult = {
  user?: User
  error?: OpenfortError
}

type GenerateSiweMessageResult = {
  message?: string
  error?: OpenfortError
}
```

## Parameters

### `generateSiweMessage`

Generates a SIWE message for the user to sign with their wallet.

```ts
type GenerateSiweOptions = {
  wallet: string | { address: string }
  from: {
    domain: string
    uri: string
  }
  onSuccess?: (data: GenerateSiweMessageResult) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```

### `signInWithSiwe`

Authenticates the user with the signed SIWE message.

```ts
type SiweSignInOptions = {
  walletAddress: string
  signature: string
  messageOverride?: string
  disableSignup?: boolean
  onSuccess?: (data: WalletAuthResult) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```

### `linkSiwe`

Links a wallet to an existing authenticated account.

```ts
type LinkSiweOptions = {
  walletAddress: string
  signature: string
  messageOverride?: string
  onSuccess?: (data: WalletAuthResult) => void
  onError?: (error: OpenfortError) => void
  throwOnError?: boolean
}
```
