# React Quickstart (/docs/quickstarts/react)

In this quickstart, you will:

- Create a MonoCloud Single Page App
- Install the MonoCloud React SDK
- Wrap your app with the `<MonoCloudAuthProvider>` so callbacks are handled for you
- Read the authenticated user and add sign-in, sign-up, and sign-out actions

## Prerequisites [#prerequisites]

Before you begin, make sure you have:

- A MonoCloud account and tenant
- Node.js 18+ (npm, Yarn, or PNPM)
- An existing Vite + React project (or run `npm create vite@latest react-quickstart -- --template react-ts`)

> A complete working example is available at: https://github.com/monocloud/react-quickstart

## Configure MonoCloud [#configure-monocloud]

1. In the [MonoCloud Dashboard](https://dashboard.monocloud.com/), create a new **Single Page App**
1. Select **React** as your stack
1. Set the following URLs for local development (assuming the Vite default port):
   - **Callback URLs:**
     `http://localhost:5173`
   - **Sign-out URLs:**
     `http://localhost:5173`
   - **Cross-Origin URLs:**
     `http://localhost:5173`

> Keep this tab open. You'll need the Domain and Client ID next.

## Install the SDK [#install-the-sdk]

Install the SDK:

```npm title="Terminal"
npm install @monocloud/auth-react
```

## Wrap your app with the provider [#wrap-your-app-with-the-provider]

Wrap your application with `<MonoCloudAuthProvider>` in `src/main.tsx`. The provider initializes the client and, by default, completes the sign-in and sign-out callbacks automatically when it mounts.

```tsx title="src/main.tsx"
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { MonoCloudAuthProvider } from "@monocloud/auth-react";
import App from "./App.tsx";

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <MonoCloudAuthProvider
      tenantDomain="https://<your-domain>"
      clientId="<your-client-id>"
    >
      <App />
    </MonoCloudAuthProvider>
  </StrictMode>
);
```

## Add the authentication code [#add-the-authentication-code]

Replace `src/App.tsx` with the following. It reads the authentication state with `useAuth()` and wires up the sign-in, sign-up, and sign-out buttons.

```tsx title="src/App.tsx"
import { useAuth, SignIn, SignUp, SignOut } from "@monocloud/auth-react";

function App() {
  const { isLoading, isAuthenticated, user } = useAuth();

  if (isLoading) {
    return <p>Loading...</p>;
  }

  if (!isAuthenticated) {
    return (
      <>
        <SignIn>Sign In</SignIn>
        <SignUp>Sign Up</SignUp>
      </>
    );
  }

  return (
    <>
      <pre>{JSON.stringify(user, null, 2)}</pre>
      <SignOut>Sign Out</SignOut>
    </>
  );
}

export default App;
```

## Run the application [#run-the-application]

Start the Vite development server:

```npm title="Terminal"
npm run dev
```

Open `http://localhost:5173` and:

- Click **Sign In** to authenticate with MonoCloud
- After redirecting back, the user object renders on the page
- Click **Sign Out** to end the session

Your React application is now authenticated with MonoCloud.

## Next steps [#next-steps]

- [Read the authentication state](/docs/sdks/react/authentication-state)
- [Sign in, sign up, and sign out](/docs/sdks/react/sign-in-out)
- [Protect content with the Protected component](/docs/sdks/react/protected)
- [Handle sign-in and sign-out callbacks](/docs/sdks/react/handle-callbacks)

👉 **[React SDK API Reference](https://monocloud.github.io/auth-js/modules/_monocloud_auth-react.html)**
