# `useOAuth`

Authenticate with third-party providers like Google, Apple, Facebook, Discord, and Twitter.

## Usage

```tsx
import { OAuthProvider, useOAuth } from '@openfort/react';

function SocialLogin() {
  const { initOAuth, linkOauth, isLoading } = useOAuth();

  const loginWithGoogle = () => initOAuth({ provider: OAuthProvider.GOOGLE });
  const linkDiscord = () => linkOauth({ provider: OAuthProvider.DISCORD });

  return null;
}
```

## Reading the wallet after sign-in

`useOAuth` is fire-and-forget — it authenticates the user, then returns. The wallet appears reactively on the chain hook a moment later, once the SDK has recovered or created it.

* **Ethereum:** read `address` / `isConnected` from [`useEthereumEmbeddedWallet`](/docs/products/embedded-wallet/react/hooks/useEthereumEmbeddedWallet).
* **Solana:** read `address` / `isConnected` from [`useSolanaEmbeddedWallet`](/docs/products/embedded-wallet/react/hooks/useSolanaEmbeddedWallet).
* Both hooks share the same connection-state shape (`isConnected`, `isConnecting`, `isDisconnected`, `isReconnecting`); use the `status` discriminated union when you need granular states like `'fetching-wallets'`, `'creating'`, or `'needs-recovery'`.
* Recovery is controlled by `recoverWalletAutomatically` (default `true`) and uses the `walletConfig.chainType` set on `OpenfortProvider`. **The default `chainType` is `EVM`** — Solana apps must set `chainType: ChainTypeEnum.SVM`, or the wallet hook will stay disconnected after OAuth.

See the [social authentication overview](/docs/products/embedded-wallet/react/auth#using-social-authentication) for end-to-end snippets, or the [headless EVM](https://github.com/openfort-xyz/openfort-react/tree/main/examples/quickstarts/headless) and [headless Solana](https://github.com/openfort-xyz/openfort-react/tree/main/examples/quickstarts/solana-headless) quickstart apps for runnable references.

## Return type

```ts
type UseOAuthReturn = {
  initOAuth(options: InitOAuthOptions): Promise<InitOAuthReturnType>
  linkOauth(options: InitOAuthOptions): Promise<InitOAuthReturnType>
  storeCredentials(options: StoreCredentialsOptions): Promise<StoreCredentialsResult>
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  error?: OpenfortError | null
}

type InitOAuthReturnType = {
  error?: OpenfortError
}

type StoreCredentialsResult = {
  user?: User
  wallet?: UserWallet
  error?: OpenfortError
}
```

## Hook options

Configure default behavior when initializing the hook.

```ts
type UseOAuthOptions = {
  // Default OAuth redirect URL.
  redirectTo?: string
  // Log out the user if wallet recovery fails. Defaults to true.
  logoutOnError?: boolean
  // Automatically recover the wallet after authentication. Defaults to true.
  recoverWalletAutomatically?: boolean
  onSuccess?: (data: StoreCredentialsResult | InitOAuthReturnType) => void
  onError?: (error: OpenfortError) => void
}
```

## Parameters

### initOAuth / linkOauth

```ts
type InitOAuthOptions = {
  provider: OAuthProvider
  redirectTo?: string
  onSuccess?: (data: InitOAuthReturnType) => void
  onError?: (error: OpenfortError) => void
}

enum OAuthProvider {
  GOOGLE = "google",
  FACEBOOK = "facebook",
  DISCORD = "discord",
  TWITTER = "twitter",
  EPIC_GAMES = "epic_games",
  APPLE = "apple",
  LINE = "line",
}
```

### storeCredentials

Store OAuth credentials manually for custom OAuth flows.

```ts
type StoreCredentialsOptions = {
  userId: string
  token: string
  // Overrides the hook-level default.
  logoutOnError?: boolean
  // Overrides the hook-level default.
  recoverWalletAutomatically?: boolean
  onSuccess?: (data: StoreCredentialsResult) => void
  onError?: (error: OpenfortError) => void
}
```
