> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.openfort.io/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# `useConnectWithSiwe`

:::info
**Ethereum only.** Lives in `@openfort/react/wagmi` and requires [wagmi setup](https://www.openfort.io/docs/products/embedded-wallet/react/hooks/useWalletAuth).
:::

Runs **only** the Sign-In with Ethereum (SIWE) step against a wallet that is already connected through wagmi. Reach for it when you build the wallet-connection UI yourself and just need Openfort to authenticate the connected wallet.

## Choosing a SIWE hook

Openfort ships two hooks for connecting external wallets (MetaMask, WalletConnect, Coinbase Wallet) with SIWE. Both are Ethereum-only and live in `@openfort/react/wagmi`.

| Hook | What it does | Reach for it when |
|------|--------------|-------------------|
| [`useWalletAuth`](https://www.openfort.io/docs/products/embedded-wallet/react/hooks/useWalletAuth) **(recommended)** | Connects the wagmi wallet **and** runs SIWE in one call. Also returns the list of available wallets and loading/error state. | You want a standard "connect wallet" list or button. |
| `useConnectWithSiwe` | Runs **only** the SIWE step on a wallet you already connected via wagmi's `useConnect`. | You manage the wagmi connection yourself in a fully custom flow. |

Internally `useWalletAuth` connects the wallet for you and then calls the same SIWE routine as `useConnectWithSiwe` — so prefer `useWalletAuth` unless you need control over the connection step.

## Usage

```tsx
import { useConnect } from 'wagmi';
import { useConnectWithSiwe } from '@openfort/react/wagmi';

function CustomWalletConnect() {
  const { connectAsync, connectors } = useConnect();
  const { connectWithSiwe } = useConnectWithSiwe();

  const handleConnect = async () => {
    // First connect the wallet using wagmi
    await connectAsync({ connector: connectors[0] });

    // Then authenticate with SIWE
    await connectWithSiwe({
      onConnect: () => console.log('Connected!'),
      onError: (message) => console.error('Error:', message),
    });
  };

  return <button onClick={handleConnect}>Connect Wallet</button>;
}
```

## Return type

```ts
type UseConnectWithSiweReturn = {
  connectWithSiwe: ConnectWithSiwe
}

type ConnectWithSiwe = (options?: SiweConnectOptions) => Promise<void>

type SiweConnectOptions = {
  // Override the connector type (defaults to the connected wallet's type).
  connectorType?: string
  // Override the wallet client type (defaults to the connected wallet's ID).
  walletClientType?: string
  // Specify a specific address to use for SIWE authentication.
  address?: `0x${string}`
  // Callback when SIWE authentication fails.
  onError?: (error: string, openfortError?: OpenfortError) => void
  // Callback when SIWE authentication succeeds.
  onConnect?: () => void
  // Link wallet to existing account instead of creating new one.
  // Defaults to true if user is already authenticated.
  link?: boolean
}
```

## Behavior

* If a user is already authenticated, the wallet will be linked to their existing account
* If no user is authenticated, a new account will be created using the wallet
* The hook requires a wallet to be connected via wagmi before calling
* Automatically handles chain switching if the account chain differs from the current chain

## Related

* [useWalletAuth](https://www.openfort.io/docs/products/embedded-wallet/react/hooks/useWalletAuth) — Recommended high-level hook (connect + SIWE) and wagmi setup guide
