@chemmangat/msal-next 4.0.2 → 4.1.0
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/CHANGELOG.md +198 -0
- package/README.md +561 -723
- package/SECURITY.md +422 -110
- package/dist/index.d.mts +124 -5
- package/dist/index.d.ts +124 -5
- package/dist/index.js +2302 -43
- package/dist/index.mjs +2240 -43
- package/dist/server.js +89 -1
- package/dist/server.mjs +86 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,204 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [4.1.0] - 2026-03-07
|
|
6
|
+
|
|
7
|
+
### 🎉 Major Release - Documentation Overhaul + Production Features
|
|
8
|
+
|
|
9
|
+
This release combines a complete documentation restructure with two highly-requested production features.
|
|
10
|
+
|
|
11
|
+
### ✨ New Features
|
|
12
|
+
|
|
13
|
+
#### 1. Fixed 'use client' Directive in Built Files 🔧
|
|
14
|
+
Resolved the issue where importing MSALProvider in layout.tsx required adding 'use client' to the layout file.
|
|
15
|
+
|
|
16
|
+
**What Changed:**
|
|
17
|
+
- Added 'use client' directive to the top of all built dist files
|
|
18
|
+
- Updated tsup build configuration to preserve React directives
|
|
19
|
+
- Users can now import MSALProvider without needing to add 'use client' to their layout
|
|
20
|
+
|
|
21
|
+
**Before:**
|
|
22
|
+
```tsx
|
|
23
|
+
// layout.tsx - Had to add 'use client' here
|
|
24
|
+
'use client';
|
|
25
|
+
|
|
26
|
+
import { MSALProvider } from '@chemmangat/msal-next';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**After:**
|
|
30
|
+
```tsx
|
|
31
|
+
// layout.tsx - No 'use client' needed!
|
|
32
|
+
import { MSALProvider } from '@chemmangat/msal-next';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
#### 2. Automatic Silent Token Refresh ⭐
|
|
36
|
+
Prevents unexpected logouts by automatically refreshing tokens before they expire.
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
<MSALProvider
|
|
40
|
+
clientId="..."
|
|
41
|
+
autoRefreshToken={true} // Enable automatic refresh
|
|
42
|
+
refreshBeforeExpiry={300} // Refresh 5 min before expiry
|
|
43
|
+
>
|
|
44
|
+
{children}
|
|
45
|
+
</MSALProvider>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Benefits:**
|
|
49
|
+
- No more unexpected logouts during active sessions
|
|
50
|
+
- Tokens refresh silently in the background
|
|
51
|
+
- Configurable refresh timing
|
|
52
|
+
- Opt-in feature (disabled by default)
|
|
53
|
+
- Zero performance impact when disabled
|
|
54
|
+
|
|
55
|
+
#### 3. New useTokenRefresh Hook
|
|
56
|
+
Monitor token expiry and show warnings to users.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
const { expiresIn, isExpiringSoon, refresh } = useTokenRefresh({
|
|
60
|
+
refreshBeforeExpiry: 300,
|
|
61
|
+
scopes: ['User.Read'],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (isExpiringSoon) {
|
|
65
|
+
return <div>⚠️ Your session will expire soon</div>;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Use Cases:**
|
|
70
|
+
- Show session expiry warnings
|
|
71
|
+
- Manual token refresh
|
|
72
|
+
- Monitor token status
|
|
73
|
+
- Custom refresh logic
|
|
74
|
+
|
|
75
|
+
#### 4. Fixed "Interaction in Progress" Issue 🐛
|
|
76
|
+
Improved sign-in button state management to prevent the common "interaction already in progress" error.
|
|
77
|
+
|
|
78
|
+
**What was fixed:**
|
|
79
|
+
- Button now properly tracks MSAL interaction state
|
|
80
|
+
- Prevents multiple simultaneous login attempts
|
|
81
|
+
- Automatically resets state when user is authenticated
|
|
82
|
+
- Better cleanup on component unmount
|
|
83
|
+
- Safety timeout for edge cases
|
|
84
|
+
|
|
85
|
+
**Before:**
|
|
86
|
+
```
|
|
87
|
+
User clicks "Sign In" → Redirects → Returns → Clicks again → "Interaction in progress" error
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**After:**
|
|
91
|
+
```
|
|
92
|
+
User clicks "Sign In" → Redirects → Returns → Button automatically disabled/enabled correctly
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 📚 Documentation Overhaul
|
|
96
|
+
|
|
97
|
+
#### Restructured README.md
|
|
98
|
+
- **Setup-First Approach** - Quick Start guide now appears at the top
|
|
99
|
+
- **Complete Setup Guide for AI Assistants** - Step-by-step instructions from A to Z
|
|
100
|
+
- **Clear Project Structure** - Shows exactly where files should be placed
|
|
101
|
+
- **Common Patterns** - Ready-to-use code examples for typical scenarios
|
|
102
|
+
- **Troubleshooting Checklist** - Quick diagnostic steps
|
|
103
|
+
- **Configuration Reference** - Complete table of all options
|
|
104
|
+
- **FAQ Section** - Answers to common questions
|
|
105
|
+
|
|
106
|
+
#### Better for AI Assistants
|
|
107
|
+
When an AI assistant is asked to "implement MSAL authentication", the README now provides:
|
|
108
|
+
1. Clear installation command
|
|
109
|
+
2. Azure AD setup steps
|
|
110
|
+
3. Environment variable configuration
|
|
111
|
+
4. Exact file structure
|
|
112
|
+
5. Complete code for each file
|
|
113
|
+
6. Common patterns
|
|
114
|
+
7. Troubleshooting steps
|
|
115
|
+
|
|
116
|
+
### 🔧 Improvements
|
|
117
|
+
|
|
118
|
+
- **MicrosoftSignInButton**: Better state management, prevents duplicate clicks
|
|
119
|
+
- **MSALProvider**: New props for automatic token refresh
|
|
120
|
+
- **Type Safety**: New types exported for token refresh functionality
|
|
121
|
+
- **Error Handling**: Better handling of interaction state
|
|
122
|
+
|
|
123
|
+
### 📦 New Exports
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// Hook
|
|
127
|
+
export { useTokenRefresh } from '@chemmangat/msal-next';
|
|
128
|
+
|
|
129
|
+
// Types
|
|
130
|
+
export type { UseTokenRefreshOptions, UseTokenRefreshReturn } from '@chemmangat/msal-next';
|
|
131
|
+
|
|
132
|
+
// MSALProvider new props
|
|
133
|
+
interface MsalAuthConfig {
|
|
134
|
+
autoRefreshToken?: boolean;
|
|
135
|
+
refreshBeforeExpiry?: number;
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 📚 New Documentation
|
|
140
|
+
|
|
141
|
+
#### SECURITY.md
|
|
142
|
+
Comprehensive security documentation covering:
|
|
143
|
+
- Security architecture and token handling
|
|
144
|
+
- Best practices for production deployment
|
|
145
|
+
- Common security mistakes to avoid
|
|
146
|
+
- Compliance information (GDPR, SOC 2, HIPAA)
|
|
147
|
+
- Security checklist for deployment
|
|
148
|
+
- Monitoring and incident response
|
|
149
|
+
|
|
150
|
+
#### Updated README.md
|
|
151
|
+
- Top features table at the beginning
|
|
152
|
+
- Prominent security highlights
|
|
153
|
+
- Clear note about 'use client' not needed in layout.tsx
|
|
154
|
+
- Security policy links throughout
|
|
155
|
+
- Enhanced setup instructions
|
|
156
|
+
|
|
157
|
+
### 🔄 Breaking Changes
|
|
158
|
+
|
|
159
|
+
**None!** This release is 100% backward compatible with v4.0.2.
|
|
160
|
+
|
|
161
|
+
### 📝 Migration from v4.0.2
|
|
162
|
+
|
|
163
|
+
No code changes required! Simply update:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm install @chemmangat/msal-next@4.1.0
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Optional: Enable automatic token refresh**
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
<MSALProvider
|
|
173
|
+
clientId="..."
|
|
174
|
+
autoRefreshToken={true} // NEW - prevents unexpected logouts
|
|
175
|
+
>
|
|
176
|
+
{children}
|
|
177
|
+
</MSALProvider>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 🎯 Use Cases
|
|
181
|
+
|
|
182
|
+
**Automatic Token Refresh:**
|
|
183
|
+
- Long-running applications
|
|
184
|
+
- Apps where users stay logged in for hours
|
|
185
|
+
- Prevent interruptions during active work
|
|
186
|
+
- Background data synchronization
|
|
187
|
+
|
|
188
|
+
**Token Expiry Monitoring:**
|
|
189
|
+
- Show session timeout warnings
|
|
190
|
+
- Implement custom refresh logic
|
|
191
|
+
- Track authentication state
|
|
192
|
+
- User experience improvements
|
|
193
|
+
|
|
194
|
+
### 📊 Impact
|
|
195
|
+
|
|
196
|
+
- **Reduced Support Tickets**: Automatic refresh prevents "why was I logged out?" questions
|
|
197
|
+
- **Better UX**: Users stay logged in during active sessions
|
|
198
|
+
- **Easier Setup**: AI assistants can now implement MSAL correctly first try
|
|
199
|
+
- **Faster Onboarding**: Developers can set up in 5 minutes with new README
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
5
203
|
## [4.0.2] - 2026-03-07
|
|
6
204
|
|
|
7
205
|
### 🎉 Developer Experience Release - Better Types, Errors & Validation
|