# `useConnectWithSiwe`

:::info
**Ethereum only.** Requires [wagmi setup](/docs/products/embedded-wallet/react/hooks/useWalletAuth).
:::

Connect to Openfort using Sign-In with Ethereum (SIWE) after a wallet has been connected via wagmi. Use for custom wallet connection flows.

## Usage

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

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

  const handleConnect = async () => {
    // First connect the wallet using wagmi
    await connect({ 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](/docs/products/embedded-wallet/react/hooks/useWalletAuth) — Setup with wagmi
