# Install and set up the MonoCloud React SDK (/docs/sdks/react/installation)

This guide shows how to install the MonoCloud React SDK and connect a React single-page application with MonoCloud authentication.

By the end of this guide, you will have:

- A MonoCloud Single Page App configured in the Dashboard
- The SDK installed in your project
- The `<MonoCloudAuthProvider>` wrapping your application

## Sign up and configure MonoCloud [#sign-up-and-configure-monocloud]

> If you already have a MonoCloud account and Single Page App, skip ahead to [Install the MonoCloud React SDK](#install-the-monocloud-react-sdk).

### Create a MonoCloud account [#create-a-monocloud-account]

If you don’t have an account yet, sign up at: [https://www.monocloud.com](https://www.monocloud.com/api/auth/signin?prompt=create)

### Create a Single Page App [#create-a-single-page-app]

<div className="max-w-md">
![Create a Single Page App](/docs/dashboard/add-a-client-react-spa-monocloud.png)
</div>

In the [MonoCloud Dashboard](https://dashboard.monocloud.com/):

1. Click **Add Application**
1. Select **Single Page App**
1. Choose **React**
1. Create the application

Each Single Page App represents a single browser-based app secured by MonoCloud.

## Configuring your Single Page App [#configuring-your-single-page-app]

Open your application and configure the following URLs.

### Redirect URLs [#redirect-urls]

These URLs tell MonoCloud where to redirect users after authentication events.

For local development with the Vite default port, configure:

- **Callback URLs:** `http://localhost:5173`
- **Sign-out URLs:** `http://localhost:5173`

By default, the provider processes the callback at your application's origin, so the callback URL is simply the URL your app is served from. If you handle the callback on a dedicated route (see [Handle sign-in and sign-out callbacks](/docs/sdks/react/handle-callbacks)), register that route instead - for example, `http://localhost:5173/callback`.

### Cross-Origin URLs [#cross-origin-urls]

A single-page app calls MonoCloud's endpoints directly from the browser, so the origin your app is served from must be allowed:

- **Cross-Origin URLs:** `http://localhost:5173`

> Replace these with your production URLs before deployment.

## Create a Vite + React project [#create-a-vite--react-project]

If you already have a project, skip this step.

```npm title="Terminal"
npm create vite@latest <your-app-name> -- --template react-ts
cd <your-app-name>
```

Node.js 18 or later is recommended.

## Install the MonoCloud React SDK [#install-the-monocloud-react-sdk]

Install the SDK using your package manager:

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

## Add the provider [#add-the-provider]

Wrap your application with `<MonoCloudAuthProvider>`. It creates a single shared `MonoCloudWebJSClient` instance and makes the authentication state and actions available to every component below it through the `useAuth()` hook.

```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>
);
```

### Configuration reference [#configuration-reference]

| Option                | Required | Description                                                                                                  |
| --------------------- | -------- | ------------------------------------------------------------------------------------------------------------ |
| `tenantDomain`        | Yes      | MonoCloud tenant domain from **Application Information** in the Dashboard                                    |
| `clientId`            | Yes      | Client ID from **Application Information** in the Dashboard                                                  |

The `<MonoCloudAuthProvider>` component accepts additional props. You can find the complete list in the [API reference](https://monocloud.github.io/auth-js/interfaces/_monocloud_auth-react.MonoCloudAuthProviderProps.html).

## Process callbacks [#process-callbacks]

By default the provider completes the sign-in and sign-out callbacks for you when it mounts - no extra wiring is required. The authentication state becomes available through `useAuth()` once the callback has been processed.

> For full details on routing, return URLs, and integrating with a client-side router, see [Handle sign-in and sign-out callbacks](/docs/sdks/react/handle-callbacks).

## Next steps [#next-steps]

Wire up the rest of the integration:

- [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)
