Skip to content

Commit b3d4888

Browse files
tnorlingCopilotCopilot
authored
Additional msal-react v5 migration details (#8386)
This pull request updates the migration documentation for both MSAL Browser and MSAL React to clarify the required steps for upgrading to v5, including payload type changes, migration paths, and compatibility notes. The changes provide explicit migration examples and highlight new requirements and breaking changes. **MSAL React v5 Migration Guidance and Compatibility:** - Added clear migration paths for upgrading from v1/v2/v3 to v5, with emphasis on following the MSAL Browser v4-v5 migration guide and setting up the required COOP redirect bridge. - Documented React version support: MSAL React v5 now requires React 19+, with notes and workarounds for temporary use on React 18, though it is not supported. **MSAL Browser v5 Event Handling Changes:** - Provided explicit guidance on handling the new `LOGIN_SUCCESS` payload type, including before/after TypeScript code samples to illustrate the migration from casting to `AuthenticationResult` to using `AccountInfo`. **InteractionStatus and Event Consolidation:** - Clarified the consolidation of `InteractionStatus` values and provided a migration example for simplifying in-progress status checks in React apps. These updates ensure developers have clear, actionable steps for migrating to the latest major versions and handling breaking changes in event payloads and interaction status. --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: tnorling <5307810+tnorling@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1d8e35f commit b3d4888

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

lib/msal-browser/docs/v4-migration.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,46 @@ We have consolidated event types and InteractionStatus to reflect what happened
418418
1. The payload for `LOGIN_SUCCESS` is now an `AccountInfo` object.
419419
1. Any successful login now emits both a `LOGIN_SUCCESS` and `ACQUIRE_TOKEN_SUCCESS` event.
420420

421+
#### `LOGIN_SUCCESS` payload type migration
422+
423+
If your event callback currently casts `LOGIN_SUCCESS` payloads to `AuthenticationResult`, update it to use `AccountInfo` for `LOGIN_SUCCESS` and reserve `AuthenticationResult` for `ACQUIRE_TOKEN_SUCCESS`.
424+
425+
```typescript
426+
// BEFORE (v4-style assumption)
427+
import {
428+
EventType,
429+
AuthenticationResult,
430+
} from "@azure/msal-browser";
431+
432+
pca.addEventCallback((event) => {
433+
if (event.eventType === EventType.LOGIN_SUCCESS) {
434+
const result = event.payload as AuthenticationResult;
435+
setAccount(result.account); // Will silently fail in v5 where payload is AccountInfo, not AuthenticationResult
436+
}
437+
});
438+
```
439+
440+
```typescript
441+
// AFTER (v5-safe handling)
442+
import {
443+
EventType,
444+
AuthenticationResult,
445+
AccountInfo,
446+
} from "@azure/msal-browser";
447+
448+
pca.addEventCallback((event) => {
449+
if (event.eventType === EventType.LOGIN_SUCCESS) {
450+
const account = event.payload as AccountInfo;
451+
setAccount(account);
452+
}
453+
454+
if (event.eventType === EventType.ACQUIRE_TOKEN_SUCCESS) {
455+
const result = event.payload as AuthenticationResult;
456+
setAccessToken(result.accessToken);
457+
}
458+
});
459+
```
460+
421461
### Error message format changes
422462

423463
To reduce bundle size, error messages have been moved out of the bundle. When an error is thrown, the `message` property now returns a generic link to the error documentation instead of a descriptive error message:

lib/msal-react/docs/migration-guide-v4-v5.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,54 @@ Note: There is no MSAL React v4 release. The package version was incremented fro
44

55
Please see the [MSAL Browser v4-v5 migration guide](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md) for browser support and other key changes.
66

7+
## Migration paths
8+
9+
- **v3 -> v5**: Follow this guide, then apply the [MSAL Browser v4-v5 migration guide](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md), especially the COOP redirect bridge setup.
10+
- **v1/v2 -> v5**: The v1 -> v2 and v2 -> v3 updates were peer dependency version updates only for most apps. Move to v3 first, then follow the v3 -> v5 guidance in this document plus COOP redirect bridge setup.
11+
12+
## COOP redirect bridge setup (required)
13+
14+
MSAL Browser v5 requires a dedicated redirect page/bridge for authentication flows.
15+
16+
Please see the [COOP section in the MSAL Browser v4-v5 migration guide](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v4-migration.md#cross-origin-opener-policy-coop-support).
17+
718
## Dropped support for old React versions
8-
MSAL React v5 supports React 19 or greater. It no longer supports React 16, 17, or 18.
19+
MSAL React v5 supports React 19.2.1 or greater. It no longer supports React 16, 17, or 18.
20+
21+
## React 18 compatibility note
22+
23+
If your app is still on React 18, installing `@azure/msal-react@^5` may fail due to peer dependency constraints.
24+
25+
- Temporary install workaround: `npm install --legacy-peer-deps`
26+
- This may allow installation and basic flows may continue to work in some apps, but React 18 is not supported or validated for v5
27+
- You may see untested behavior around rendering/lifecycle timing, StrictMode interactions, or future patch updates
28+
29+
For production workloads, upgrade React to 19.2.1 or greater before moving to `@azure/msal-react@^5`.
930

1031
## Correct logout bug
1132
MSAL React v5 has fixed a bug affecting the `useMsalAuthentication` hook and `MsalAuthenticationTemplate`. Logging out now clears all state associated with the user.
1233

1334
## `InteractionStatus` changes
14-
For `InteractionStatus`: `Login`, `SsoSilent`, and `AcquireToken` are now consolidated into `AcquireToken`.
35+
For `InteractionStatus`: `Login`, `SsoSilent`, and `AcquireToken` are now consolidated into `AcquireToken`.
36+
37+
### Migration example
38+
39+
If your app previously checked multiple in-progress statuses, simplify to the consolidated `AcquireToken` status.
40+
41+
```ts
42+
import { InteractionStatus } from "@azure/msal-browser";
43+
44+
// Before (v3-style checks)
45+
const tokenInteractionInProgress =
46+
inProgress === InteractionStatus.Login ||
47+
inProgress === InteractionStatus.SsoSilent ||
48+
inProgress === InteractionStatus.AcquireToken;
49+
50+
// After (v5)
51+
const tokenInteractionInProgress =
52+
inProgress === InteractionStatus.AcquireToken;
53+
54+
if (!tokenInteractionInProgress) {
55+
// safe to initiate a new auth/token request
56+
}
57+
```

0 commit comments

Comments
 (0)