> ## Documentation Index
> Fetch the complete documentation index at: https://www.offlineprotocol.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Building a React Social App with Offline ID

> Step-by-step guide to integrating Offline Protocol ID into your social app.

### 1. **Download the Offline Protocol SDK**

Install the SDK into your React project:

```bash theme={null}
npm install @offline-protocol/id-react
```

or

```bash theme={null}
yarn add @offline-protocol/id-react
```

### 2. Setup the OfflineProvider

Wrap your app’s root layout (layout.tsx or index.tsx) with the OfflineProvider to enable authentication and connections across the app.

```typescript layout.tsx theme={null}
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";

const geistSans = Geist({
  variable: "--font-geist-sans",
  subsets: ["latin"],
});

const geistMono = Geist_Mono({
  variable: "--font-geist-mono",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      >
        <OfflineAppProvider projectId={your_project_id_key}>
          {children}
        </OfflineAppProvider>
      </body>
    </html>
  );
}
```

### 3. Handle Authentication

Use the `useAuth` hook to check if the user is logged in. If the user object is null, show the login form; otherwise, render the main app.

```typescript theme={null}
export default function App() {
  const { user, loginWithModal } = useAuth();

  if (!user) {
    return (
      <button
        className="px-6 py-3 bg-blue-600 text-white font-semibold rounded-lg hover:bg-blue-700 transition-all"
        onClick={loginWithModal}
      >
        Get Started
      </button>
    );
  }
  return <UserProfile />;
}
```

<img src="https://mintcdn.com/offlineprotocol/zMDWYgS7FPAxKfsX/images/examples/login1.png?fit=max&auto=format&n=zMDWYgS7FPAxKfsX&q=85&s=bfda60a6d6d3bffd3baf713690295a34" alt="Email input" width="2880" height="1720" data-path="images/examples/login1.png" />

### 4. Request Login Code and Verify

<img src="https://mintcdn.com/offlineprotocol/zMDWYgS7FPAxKfsX/images/examples/login2.png?fit=max&auto=format&n=zMDWYgS7FPAxKfsX&q=85&s=43edfe9a38007e2fefbf14f95d4cf2c5" alt="Email Verify Code" width="2880" height="1722" data-path="images/examples/login2.png" />

### 5. First Login Experience

After signing in, users will land on the home page where their existing profiles and connections are automatically synced from Offline Protocol. Display the connections or profiles and other details the way you prefer.

<img src="https://mintcdn.com/offlineprotocol/Q1-AWjiPKXNyD3Nz/images/examples/profile-home.jpeg?fit=max&auto=format&n=Q1-AWjiPKXNyD3Nz&q=85&s=d8aced4185a45ebe1ecb1f786fb934ed" alt="Home" width="1267" height="723" data-path="images/examples/profile-home.jpeg" />
