@chemmangat/msal-next 3.0.8 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION_GUIDE_v3.md +367 -0
- package/README.md +4 -2
- package/package.json +4 -4
- package/RELEASE_NOTES_v3.0.8.md +0 -70
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
# Migration Guide: v2.x to v3.0.0
|
|
2
|
+
|
|
3
|
+
This guide will help you migrate from @chemmangat/msal-next v2.x to v3.0.0.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
v3.0.0 is a major release with breaking changes focused on:
|
|
8
|
+
- Updated minimum requirements
|
|
9
|
+
- Removed deprecated APIs
|
|
10
|
+
- Enhanced debugging capabilities
|
|
11
|
+
- New CLI tool for easier setup
|
|
12
|
+
|
|
13
|
+
## Quick Migration Checklist
|
|
14
|
+
|
|
15
|
+
- [ ] Update Node.js to v18+
|
|
16
|
+
- [ ] Update Next.js to v14.1+
|
|
17
|
+
- [ ] Update MSAL packages to v4+
|
|
18
|
+
- [ ] Update @chemmangat/msal-next to v3.0.0
|
|
19
|
+
- [ ] Remove usage of deprecated APIs
|
|
20
|
+
- [ ] Test your application thoroughly
|
|
21
|
+
|
|
22
|
+
## Step-by-Step Migration
|
|
23
|
+
|
|
24
|
+
### 1. Update Node.js
|
|
25
|
+
|
|
26
|
+
v3.0.0 requires Node.js 18 or higher.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Check your current version
|
|
30
|
+
node --version
|
|
31
|
+
|
|
32
|
+
# If < 18, update Node.js
|
|
33
|
+
# Using nvm:
|
|
34
|
+
nvm install 18
|
|
35
|
+
nvm use 18
|
|
36
|
+
|
|
37
|
+
# Or download from nodejs.org
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Update Dependencies
|
|
41
|
+
|
|
42
|
+
Update your `package.json`:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Update core packages
|
|
46
|
+
npm install @chemmangat/msal-next@^3.0.0
|
|
47
|
+
npm install @azure/msal-browser@^4.0.0
|
|
48
|
+
npm install @azure/msal-react@^3.0.0
|
|
49
|
+
npm install next@^14.1.0
|
|
50
|
+
|
|
51
|
+
# Or use the CLI
|
|
52
|
+
npx @chemmangat/msal-next init
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Before** (package.json):
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@chemmangat/msal-next": "^2.3.0",
|
|
60
|
+
"@azure/msal-browser": "^3.11.0",
|
|
61
|
+
"@azure/msal-react": "^2.0.0",
|
|
62
|
+
"next": "^14.0.0"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**After** (package.json):
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@chemmangat/msal-next": "^3.0.0",
|
|
72
|
+
"@azure/msal-browser": "^4.0.0",
|
|
73
|
+
"@azure/msal-react": "^3.0.0",
|
|
74
|
+
"next": "^14.1.0"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. Remove Deprecated APIs
|
|
80
|
+
|
|
81
|
+
#### ServerSession.accessToken
|
|
82
|
+
|
|
83
|
+
The `ServerSession.accessToken` property has been removed for security reasons.
|
|
84
|
+
|
|
85
|
+
**Before** (v2.x):
|
|
86
|
+
```typescript
|
|
87
|
+
// ❌ This no longer works
|
|
88
|
+
import { getServerSession } from '@chemmangat/msal-next/server';
|
|
89
|
+
|
|
90
|
+
export default async function Page() {
|
|
91
|
+
const session = await getServerSession();
|
|
92
|
+
const token = session.accessToken; // ❌ Removed
|
|
93
|
+
|
|
94
|
+
// Use token for API calls
|
|
95
|
+
const response = await fetch('https://graph.microsoft.com/v1.0/me', {
|
|
96
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**After** (v3.0.0):
|
|
102
|
+
```typescript
|
|
103
|
+
// ✅ Use client-side token acquisition
|
|
104
|
+
'use client';
|
|
105
|
+
|
|
106
|
+
import { useMsalAuth } from '@chemmangat/msal-next';
|
|
107
|
+
|
|
108
|
+
export default function Page() {
|
|
109
|
+
const { acquireToken } = useMsalAuth();
|
|
110
|
+
|
|
111
|
+
const fetchData = async () => {
|
|
112
|
+
const token = await acquireToken(['User.Read']);
|
|
113
|
+
|
|
114
|
+
const response = await fetch('https://graph.microsoft.com/v1.0/me', {
|
|
115
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return <button onClick={fetchData}>Fetch Data</button>;
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Alternative**: Use the `useGraphApi` hook:
|
|
124
|
+
```typescript
|
|
125
|
+
'use client';
|
|
126
|
+
|
|
127
|
+
import { useGraphApi } from '@chemmangat/msal-next';
|
|
128
|
+
|
|
129
|
+
export default function Page() {
|
|
130
|
+
const graph = useGraphApi();
|
|
131
|
+
|
|
132
|
+
const fetchData = async () => {
|
|
133
|
+
const user = await graph.get('/me');
|
|
134
|
+
console.log(user);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return <button onClick={fetchData}>Fetch Data</button>;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 4. Update Debug Configuration
|
|
142
|
+
|
|
143
|
+
The debug logger has been enhanced with new options.
|
|
144
|
+
|
|
145
|
+
**Before** (v2.x):
|
|
146
|
+
```typescript
|
|
147
|
+
<MsalAuthProvider
|
|
148
|
+
clientId={process.env.NEXT_PUBLIC_CLIENT_ID!}
|
|
149
|
+
enableLogging={true}
|
|
150
|
+
>
|
|
151
|
+
{children}
|
|
152
|
+
</MsalAuthProvider>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**After** (v3.0.0) - Same API, but with new capabilities:
|
|
156
|
+
```typescript
|
|
157
|
+
<MsalAuthProvider
|
|
158
|
+
clientId={process.env.NEXT_PUBLIC_CLIENT_ID!}
|
|
159
|
+
enableLogging={true}
|
|
160
|
+
// New: Enhanced logging is automatic
|
|
161
|
+
>
|
|
162
|
+
{children}
|
|
163
|
+
</MsalAuthProvider>
|
|
164
|
+
|
|
165
|
+
// Access enhanced logger features
|
|
166
|
+
import { getDebugLogger } from '@chemmangat/msal-next';
|
|
167
|
+
|
|
168
|
+
const logger = getDebugLogger({
|
|
169
|
+
enabled: true,
|
|
170
|
+
enablePerformance: true, // NEW
|
|
171
|
+
enableNetworkLogs: true, // NEW
|
|
172
|
+
maxHistorySize: 100, // NEW
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// NEW: Performance tracking
|
|
176
|
+
logger.startTiming('operation');
|
|
177
|
+
// ... do work
|
|
178
|
+
logger.endTiming('operation');
|
|
179
|
+
|
|
180
|
+
// NEW: Export logs
|
|
181
|
+
logger.downloadLogs();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 5. Update TypeScript Configuration (if needed)
|
|
185
|
+
|
|
186
|
+
Ensure your `tsconfig.json` is compatible:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"compilerOptions": {
|
|
191
|
+
"target": "ES2020",
|
|
192
|
+
"lib": ["ES2020", "DOM"],
|
|
193
|
+
"module": "ESNext",
|
|
194
|
+
"moduleResolution": "bundler",
|
|
195
|
+
"strict": true
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## New Features You Can Use
|
|
201
|
+
|
|
202
|
+
### 1. CLI Tool
|
|
203
|
+
|
|
204
|
+
Use the new CLI for easier setup:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Initialize in existing project
|
|
208
|
+
npx @chemmangat/msal-next init
|
|
209
|
+
|
|
210
|
+
# Add components
|
|
211
|
+
npx @chemmangat/msal-next add auth-guard
|
|
212
|
+
|
|
213
|
+
# Configure Azure AD
|
|
214
|
+
npx @chemmangat/msal-next configure
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 2. Enhanced Debug Logger
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { getDebugLogger } from '@chemmangat/msal-next';
|
|
221
|
+
|
|
222
|
+
const logger = getDebugLogger({
|
|
223
|
+
enabled: true,
|
|
224
|
+
level: 'debug',
|
|
225
|
+
enablePerformance: true,
|
|
226
|
+
enableNetworkLogs: true,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Track performance
|
|
230
|
+
logger.startTiming('token-acquisition');
|
|
231
|
+
const token = await acquireToken(['User.Read']);
|
|
232
|
+
logger.endTiming('token-acquisition');
|
|
233
|
+
|
|
234
|
+
// Log network requests
|
|
235
|
+
logger.logRequest('GET', '/me');
|
|
236
|
+
logger.logResponse('GET', '/me', 200, userData);
|
|
237
|
+
|
|
238
|
+
// Export logs for debugging
|
|
239
|
+
logger.downloadLogs('debug-logs.json');
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 3. New Examples
|
|
243
|
+
|
|
244
|
+
Check out the new examples in `src/examples/`:
|
|
245
|
+
- Role-based routing
|
|
246
|
+
- Multi-tenant SaaS
|
|
247
|
+
- API route protection
|
|
248
|
+
- Graph API integration
|
|
249
|
+
|
|
250
|
+
## Common Issues and Solutions
|
|
251
|
+
|
|
252
|
+
### Issue: "Module not found: @azure/msal-browser"
|
|
253
|
+
|
|
254
|
+
**Solution**: Update to MSAL v4:
|
|
255
|
+
```bash
|
|
256
|
+
npm install @azure/msal-browser@^4.0.0 @azure/msal-react@^3.0.0
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Issue: "ServerSession.accessToken is undefined"
|
|
260
|
+
|
|
261
|
+
**Solution**: This property was removed. Use client-side token acquisition:
|
|
262
|
+
```typescript
|
|
263
|
+
const { acquireToken } = useMsalAuth();
|
|
264
|
+
const token = await acquireToken(['User.Read']);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Issue: "Node.js version not supported"
|
|
268
|
+
|
|
269
|
+
**Solution**: Update to Node.js 18+:
|
|
270
|
+
```bash
|
|
271
|
+
nvm install 18
|
|
272
|
+
nvm use 18
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Issue: TypeScript errors after upgrade
|
|
276
|
+
|
|
277
|
+
**Solution**: Update TypeScript and type definitions:
|
|
278
|
+
```bash
|
|
279
|
+
npm install -D typescript@^5.3.0
|
|
280
|
+
npm install -D @types/react@^18.2.0
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Testing Your Migration
|
|
284
|
+
|
|
285
|
+
After migrating, test these critical paths:
|
|
286
|
+
|
|
287
|
+
1. **Authentication Flow**
|
|
288
|
+
```typescript
|
|
289
|
+
// Test login
|
|
290
|
+
await loginPopup();
|
|
291
|
+
|
|
292
|
+
// Test token acquisition
|
|
293
|
+
const token = await acquireToken(['User.Read']);
|
|
294
|
+
|
|
295
|
+
// Test logout
|
|
296
|
+
await logoutPopup();
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
2. **Protected Routes**
|
|
300
|
+
- Visit protected pages
|
|
301
|
+
- Verify redirects work
|
|
302
|
+
- Check middleware behavior
|
|
303
|
+
|
|
304
|
+
3. **API Calls**
|
|
305
|
+
- Test Graph API calls
|
|
306
|
+
- Verify token refresh
|
|
307
|
+
- Check error handling
|
|
308
|
+
|
|
309
|
+
4. **Components**
|
|
310
|
+
- Test all auth components
|
|
311
|
+
- Verify UI renders correctly
|
|
312
|
+
- Check loading states
|
|
313
|
+
|
|
314
|
+
## Rollback Plan
|
|
315
|
+
|
|
316
|
+
If you encounter issues, you can rollback:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# Rollback to v2.3.0
|
|
320
|
+
npm install @chemmangat/msal-next@2.3.0
|
|
321
|
+
npm install @azure/msal-browser@^3.11.0
|
|
322
|
+
npm install @azure/msal-react@^2.0.0
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Getting Help
|
|
326
|
+
|
|
327
|
+
If you need assistance:
|
|
328
|
+
|
|
329
|
+
1. **Documentation**: Check the [README](./README.md) and [SECURITY.md](./SECURITY.md)
|
|
330
|
+
2. **Examples**: Review examples in `src/examples/`
|
|
331
|
+
3. **Issues**: Open an issue on [GitHub](https://github.com/chemmangat/msal-next/issues)
|
|
332
|
+
4. **Discussions**: Ask questions in [GitHub Discussions](https://github.com/chemmangat/msal-next/discussions)
|
|
333
|
+
|
|
334
|
+
## Automated Migration (Coming Soon)
|
|
335
|
+
|
|
336
|
+
We're working on an automated migration tool:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# Future feature
|
|
340
|
+
npx @chemmangat/msal-next migrate
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
This will automatically:
|
|
344
|
+
- Update dependencies
|
|
345
|
+
- Remove deprecated code
|
|
346
|
+
- Update configuration
|
|
347
|
+
- Generate migration report
|
|
348
|
+
|
|
349
|
+
## Summary
|
|
350
|
+
|
|
351
|
+
v3.0.0 brings enhanced debugging, a new CLI tool, and better developer experience. While there are breaking changes, the migration path is straightforward:
|
|
352
|
+
|
|
353
|
+
1. Update Node.js to 18+
|
|
354
|
+
2. Update dependencies
|
|
355
|
+
3. Remove `ServerSession.accessToken` usage
|
|
356
|
+
4. Test thoroughly
|
|
357
|
+
|
|
358
|
+
The new features make it worth the upgrade!
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
**Need Help?** Open an issue or discussion on GitHub.
|
|
363
|
+
**Found a Bug?** Please report it with reproduction steps.
|
|
364
|
+
**Have Feedback?** We'd love to hear from you!
|
|
365
|
+
|
|
366
|
+
**Last Updated**: March 5, 2026
|
|
367
|
+
**Version**: 3.0.0
|
package/README.md
CHANGED
|
@@ -5,7 +5,9 @@ Production-grade MSAL authentication library for Next.js App Router with minimal
|
|
|
5
5
|
[](https://www.npmjs.com/package/@chemmangat/msal-next)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
|
-
>
|
|
8
|
+
> **📦 Current Version: 3.0.8** - Critical bug fixes for popup authentication. [See changelog](./CHANGELOG.md)
|
|
9
|
+
|
|
10
|
+
> **⚠️ Important:** If you're on v3.0.6 or v3.0.7, please update immediately - those versions have a critical popup authentication bug.
|
|
9
11
|
|
|
10
12
|
> **Having issues?** Check the [Troubleshooting Guide](./TROUBLESHOOTING.md) for common problems and solutions.
|
|
11
13
|
|
|
@@ -82,7 +84,7 @@ npx @chemmangat/msal-next init
|
|
|
82
84
|
|
|
83
85
|
### Option 2: Manual Installation
|
|
84
86
|
```bash
|
|
85
|
-
npm install @chemmangat/msal-next@
|
|
87
|
+
npm install @chemmangat/msal-next@latest @azure/msal-browser@^4.0.0 @azure/msal-react@^3.0.0
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
## Quick Start
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chemmangat/msal-next",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Production-grade MSAL authentication package for Next.js App Router with minimal boilerplate",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist",
|
|
22
22
|
"README.md",
|
|
23
|
-
"SECURITY.md",
|
|
24
|
-
"TROUBLESHOOTING.md",
|
|
25
23
|
"CHANGELOG.md",
|
|
26
|
-
"
|
|
24
|
+
"MIGRATION_GUIDE_v3.md",
|
|
25
|
+
"SECURITY.md",
|
|
26
|
+
"TROUBLESHOOTING.md"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsup",
|
package/RELEASE_NOTES_v3.0.8.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Release Notes - v3.0.8 (Critical Bug Fix)
|
|
2
|
-
|
|
3
|
-
## 🚨 Critical Update Required
|
|
4
|
-
|
|
5
|
-
If you're using v3.0.6 or v3.0.7, please update immediately. These versions have a critical bug that breaks popup authentication.
|
|
6
|
-
|
|
7
|
-
## What Happened?
|
|
8
|
-
|
|
9
|
-
In v3.0.6, we attempted to fix a popup redirect issue by skipping `handleRedirectPromise()` in popup windows. This was incorrect and broke the authentication flow for popup-based logins.
|
|
10
|
-
|
|
11
|
-
## The Fix
|
|
12
|
-
|
|
13
|
-
v3.0.8 properly handles the popup flow by:
|
|
14
|
-
1. Calling `handleRedirectPromise()` in ALL windows (main and popup)
|
|
15
|
-
2. Only cleaning the URL in the main window
|
|
16
|
-
3. Allowing the popup to close naturally after MSAL processes the redirect
|
|
17
|
-
|
|
18
|
-
## Update Instructions
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @chemmangat/msal-next@3.0.8
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
No code changes required. Your existing implementation will work correctly.
|
|
25
|
-
|
|
26
|
-
## Verified Scenarios
|
|
27
|
-
|
|
28
|
-
### ✅ Working
|
|
29
|
-
- Popup login flow
|
|
30
|
-
- Redirect login flow
|
|
31
|
-
- User cancellation
|
|
32
|
-
- Page refresh during auth
|
|
33
|
-
- Multiple tabs
|
|
34
|
-
- Token acquisition
|
|
35
|
-
- Logout flows
|
|
36
|
-
- SSR/hydration
|
|
37
|
-
|
|
38
|
-
### ✅ Fixed Issues
|
|
39
|
-
- Popup not closing after authentication
|
|
40
|
-
- URL showing auth code after login
|
|
41
|
-
- Button staying disabled after popup closes
|
|
42
|
-
- Redirect happening in popup window
|
|
43
|
-
|
|
44
|
-
## For Users on v2.x
|
|
45
|
-
|
|
46
|
-
If you're still on v2.x, you can safely upgrade to v3.0.8. All v2.x functionality is preserved with additional improvements.
|
|
47
|
-
|
|
48
|
-
## Support
|
|
49
|
-
|
|
50
|
-
If you encounter any issues:
|
|
51
|
-
1. Check the [Troubleshooting Guide](./TROUBLESHOOTING.md)
|
|
52
|
-
2. Review [Test Scenarios](./TEST_SCENARIOS.md)
|
|
53
|
-
3. Open an issue on GitHub with:
|
|
54
|
-
- Your version number
|
|
55
|
-
- Browser and OS
|
|
56
|
-
- Steps to reproduce
|
|
57
|
-
- Console errors
|
|
58
|
-
|
|
59
|
-
## Apology
|
|
60
|
-
|
|
61
|
-
We sincerely apologize for the disruption caused by v3.0.6 and v3.0.7. We've implemented additional testing procedures to prevent similar issues in the future.
|
|
62
|
-
|
|
63
|
-
## Next Steps
|
|
64
|
-
|
|
65
|
-
1. Update to v3.0.8
|
|
66
|
-
2. Test your authentication flows
|
|
67
|
-
3. Report any issues immediately
|
|
68
|
-
4. Consider implementing the test scenarios in your own testing
|
|
69
|
-
|
|
70
|
-
Thank you for your patience and continued use of @chemmangat/msal-next.
|