# How do I integrate \*\*Auth0\*\* authentication with React 19 + React Router 7 (Vite + Netlify) and embed the default login page?

**URL:** <https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815>\
**Category:** Dev to Dev Hub\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [May 16, 2025, 11:04am UTC](https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815 "2025-05-16T11:04:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alessiopersichetti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alessiopersichetti/32/70826_2.png) [@alessiopersichetti](https://community.auth0.com/u/alessiopersichetti)\
**Post date:** [May 16, 2025, 11:04am UTC](https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815/1 "2025-05-16T11:04:47Z")

</div>

**Problem**

I’m building a SPA with **React 19.1.0** and **react-router 7.5.3** (Vite 6.3.5).  
To handle login + RBAC I chose **Auth0**.  
Auth0’s React docs target React Router 5/6 APIs, so I’m struggling to adapt them to v7.

Below is my full **`package.json`** for reference:

```json
{
  "name": "e23-platform",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "react-router build && node netlify/prepare.js",
    "dev": "cross-env NODE_ENV=development node ./dev-server.js",
    "start": "netlify serve",
    "typecheck": "react-router typegen && tsc"
  },
  "dependencies": {
    "@auth0/auth0-react": "^2.3.0",
    "@netlify/functions": "3.1.2",
    "@netlify/vite-plugin-react-router": "^1.0.1",
    "@react-router/node": "^7.5.3",
    "isbot": "^5.1.27",
    "react": "^19.1.0",
    "react-dom": "^19.1.0",
    "react-router": "^7.5.3"
  },
  "devDependencies": {
    "@mjackson/node-fetch-server": "0.6.1",
    "@react-router/dev": "^7.5.3",
    "@tailwindcss/vite": "^4.1.5",
    "@types/express": "^5.0.1",
    "@types/react": "^19.1.3",
    "@types/react-dom": "^19.1.3",
    "cross-env": "^7.0.3",
    "express": "^5.1.0",
    "netlify-cli": "^20.1.1",
    "tailwindcss": "^4.1.5",
    "typescript": "^5.8.3",
    "vite": "^6.3.5",
    "vite-tsconfig-paths": "^5.1.4"
  }
}

```

**What I’ve tried**

1. Installed the SDK:

```bash
npm i @auth0/auth0-react

```

1. Wrapped the app in `Auth0Provider`:

````tsx
// auth0.tsx
import { Auth0Provider, type AppState } from "@auth0/auth0-react";
import React, { type JSX, type PropsWithChildren } from "react";
import { useNavigate } from "react-router";

interface Auth0ProviderWithNavigateProps {
  children: React.ReactNode;
}

export const Auth0ProviderWithNavigate = ({
  children,
}: PropsWithChildren<Auth0ProviderWithNavigateProps>): JSX.Element | null => {
  const navigate = useNavigate();

  const domain = process.env.REACT_APP_AUTH0_DOMAIN;
  const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;
  const redirectUri = process.env.REACT_APP_AUTH0_CALLBACK_URL;

  const onRedirectCallback = (appState?: AppState) => {
    navigate(appState?.returnTo || window.location.pathname || "/");
  };

  if (!(domain && clientId && redirectUri)) {
    return null;
  }

  return (
    <Auth0Provider
      domain={domain}
      clientId={clientId}
      authorizationParams={{
        redirect_uri: redirectUri,
      }}
      onRedirectCallback={onRedirectCallback}
    >
      {children}
    </Auth0Provider>
  );
};```

3. Tried to protect a route with `withAuthenticationRequired` inside a **React Router 7** route config, how can I make it?:

```tsx
// routes.tsx
export default [
  index("routes/home.tsx"),
  route("login", "routes/login.tsx"),
  route("forgot-password", "routes/forgot-password.tsx"),
  route("reset-password", "routes/reset-password.tsx")
] satisfies RouteConfig;

````

**Questions**

1. What is the idiomatic way to guard routes with **Auth0** when using **React Router 7**?
2. How can I mount the Auth0 hosted login page (or their ready-made `Login component`) inside my layout instead of a full-page redirect?

**Environment**

- React 19.1.0
- react-router-dom 7.2.0
- @auth0/auth0-react 2.3.0
- Vite 6.3.5 (+ `@netlify/vite-plugin-react-router`)
- TypeScript 5.8.3
- Node 20.11.0
- Build target: Netlify Functions (no Express backend yet)

_I’ve read Auth0’s “React Quickstart” and “RBAC” guides, but they rely on `<Route render={...}>` and other v5/v7 patterns._

Any pointers or working v7 snippets would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [May 16, 2025, 6:59pm UTC](https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815/3 "2025-05-16T18:59:50Z")

</div>

Hi @alessiopersichetti,

Welcome to the Auth0 Community!

> [@alessiopersichetti](#):
>
> What is the idiomatic way to guard routes with **Auth0** when using **React Router 7**?

I have researched both React Router v6 and v7 route guards and learned that they are implemented similarly because the [public API for route protection](https://api.reactrouter.com/v7/functions/react_router.Routes.html) hasn’t changed between the versions. This means you can continue using the same logic for guarding routes in both versions. Additionally, the [Upgrading from v6 | React Router](https://reactrouter.com/upgrading/v6) documentation specifically mentions (“theoretically”) no breaking changes between v6 and v7.

I should also add that we have a backlog item to update our guide to include the SDK integration for React Router v7. For now, we have an example on using React Router 6: [React Authentication By Example: Using React Router 6](https://developer.auth0.com/resources/guides/spa/react/basic-authentication)

> [@alessiopersichetti](#):
>
> How can I mount the Auth0 hosted login page (or their ready-made `Login component`) inside my layout instead of a full-page redirect?

While we recommend using Universal Login for login, you can still do this through [embedded login](https://auth0.com/docs/authenticate/login/embedded-login). However, it’s essential to be aware of this approach’s [security risks](https://auth0.com/docs/authenticate/login/universal-vs-embedded-login#security-risks).

Let me know if you have any other questions.

Kind regards,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 30, 2025, 6:59pm UTC](https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815/4 "2025-05-30T18:59:53Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [September 5, 2025, 8:40pm UTC](https://community.auth0.com/t/how-do-i-integrate-auth0-authentication-with-react-19-react-router-7-vite-netlify-and-embed-the-default-login-page/186815/5 "2025-09-05T20:40:38Z")

</div>


