You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/msal-browser/docs/redirect-bridge.md
+2-111Lines changed: 2 additions & 111 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,8 @@ export default defineConfig({
114
114
115
115
During development (`vite dev`), the redirect page is automatically served at `/redirect.html`. In production builds, Rollup will emit both `index.html` and `redirect.html` in the output directory.
116
116
117
+
> **Sample:** See the [react-router-sample](../../../samples/msal-react-samples/react-router-sample), [typescript-sample](../../../samples/msal-react-samples/typescript-sample), and [b2c-sample](../../../samples/msal-react-samples/b2c-sample).
118
+
117
119
## Webpack
118
120
119
121
Webpack requires a dedicated entry point and an `HtmlWebpackPlugin` instance for the redirect page.
@@ -253,117 +255,6 @@ No `next.config.js` changes are needed for either router — Next.js serves page
253
255
254
256
> **Sample:** See the [nextjs-sample](../../../samples/msal-react-samples/nextjs-sample) for a Pages Router example.
255
257
256
-
## Create React App (CRA)
257
-
258
-
The recommended approach for CRA is to use a **dedicated static HTML file** placed in the `public/` folder. CRA copies everything in `public/` to the build output as-is, so `public/redirect.html` is served at `/redirect.html` with no React bundle attached — exactly what the redirect bridge requires.
259
-
260
-
### Recommended: dedicated `public/redirect.html`
261
-
262
-
1.**Create `public/redirect.html`**:
263
-
264
-
```html
265
-
<!DOCTYPE html>
266
-
<html>
267
-
<head>
268
-
<metacharset="UTF-8">
269
-
<title>Redirect</title>
270
-
</head>
271
-
<body>
272
-
<p>Processing authentication...</p>
273
-
<!--
274
-
Ensure that msal-redirect-bridge.min.js (the UMD bundle) is hosted at this path,
275
-
for example by copying it from the @azure/msal-browser package into your public/ folder.
This page is served as plain HTML — it does **not** load your React application bundle, React Router, or `MsalProvider`. No changes to `App.js` or routing are required.
299
-
300
-
> **Important:** The `public/redirect.html` example above uses the UMD bundle (`msal-redirect-bridge.min.js`) and the global `msalRedirectBridge` object. This makes the page usable in a wide range of browsers, including those that do not support native ES modules. If you prefer to use an ES module instead, you can replace the UMD `<script>` tag with a `<script type="module">` block that imports `broadcastResponseToMainFrame` from `@azure/msal-browser/redirect-bridge`, or you can use the SPA route approach described below.
301
-
302
-
### Alternative: SPA route (React Router)
303
-
304
-
> **Caveat:** This approach mounts the redirect URI inside the React Router SPA, so the **full application bundle** — including React, React Router, and all your app code — is downloaded and executed on the redirect page. For most apps the extra overhead is negligible, but it can slow down the authentication round-trip. If you use hash-based routing (`HashRouter`) you will also need to ensure the redirect URI hash is not consumed by the router before `broadcastResponseToMainFrame` runs.
305
-
306
-
If you prefer to keep everything inside the SPA, follow these steps to create a dedicated route that runs the bridge script and place it **outside**`MsalProvider`:
> **Sample:** See the [react-router-sample](../../../samples/msal-react-samples/react-router-sample) and [typescript-sample](../../../samples/msal-react-samples/typescript-sample).
366
-
367
258
## Express.js / Node.js Backend
368
259
369
260
When using Express.js (or any Node.js backend serving static files), configure the server to serve the redirect page **without** COOP headers:
@@ -28,6 +30,72 @@ If your app is still on React 18, installing `@azure/msal-react@^5` may fail due
28
30
29
31
For production workloads, upgrade React to 19.2.1 or greater before moving to `@azure/msal-react@^5`.
30
32
33
+
## Migrating from Create React App (react-scripts)
34
+
35
+
Create React App is deprecated and `react-scripts` does not support React 19. If your app uses `react-scripts`, you **must** migrate to a different build tool before upgrading to `@azure/msal-react@^5`.
36
+
37
+
**Recommended: Migrate to [Vite](https://vite.dev/)**
38
+
39
+
1. Remove `react-scripts` and install Vite + the React plugin:
40
+
```bash
41
+
npm uninstall react-scripts
42
+
npm install --save-dev vite @vitejs/plugin-react
43
+
```
44
+
45
+
2. Add `"type": "module"` to `package.json`.
46
+
47
+
3. Move `public/index.html` to the project root as `index.html`, replace `%PUBLIC_URL%/` references with `/`, and add the entry point script tag:
48
+
```html
49
+
<!-- Before (CRA): no script tag needed, CRA injects it -->
9. Set up the [redirect bridge](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/redirect-bridge.md#vite) for your Vite app.
96
+
97
+
>**Samples:** See the [react-router-sample](../../../samples/msal-react-samples/react-router-sample), [typescript-sample](../../../samples/msal-react-samples/typescript-sample), and [b2c-sample](../../../samples/msal-react-samples/b2c-sample) forcomplete Vite-based examples.
98
+
31
99
## Correct logout bug
32
100
MSAL React v5 has fixed a bug affecting the `useMsalAuthentication` hook and `MsalAuthenticationTemplate`. Logging out now clears all state associated with the user.
0 commit comments