@chemmangat/msal-next 3.0.2 → 3.0.4
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/README.md +54 -14
- package/TROUBLESHOOTING.md +294 -0
- package/dist/chunk-AD43IVG7.mjs +51 -0
- package/dist/index.d.mts +30 -49
- package/dist/index.d.ts +30 -49
- package/dist/index.js +1686 -2
- package/dist/index.mjs +1595 -2
- package/dist/server.js +115 -1
- package/dist/server.mjs +72 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ Production-grade MSAL authentication library for Next.js App Router with minimal
|
|
|
7
7
|
|
|
8
8
|
> **v3.0.0 is here!** 🎉 New CLI tool, enhanced debugging, and better DX. [See what's new](#whats-new-in-v30)
|
|
9
9
|
|
|
10
|
+
> **Having issues?** Check the [Troubleshooting Guide](./TROUBLESHOOTING.md) for common problems and solutions.
|
|
11
|
+
|
|
10
12
|
## Features
|
|
11
13
|
|
|
12
14
|
✨ **CLI Setup** - Get started in under 2 minutes with `npx @chemmangat/msal-next init`
|
|
@@ -85,19 +87,24 @@ npm install @chemmangat/msal-next@3.0.0 @azure/msal-browser@^4.0.0 @azure/msal-r
|
|
|
85
87
|
|
|
86
88
|
## Quick Start
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
> **Important:** Use `MSALProvider` (not `MsalAuthProvider`) in your layout.tsx to avoid the "createContext only works in Client Components" error.
|
|
91
|
+
|
|
92
|
+
### 1. Wrap your app with MSALProvider
|
|
89
93
|
|
|
90
94
|
```tsx
|
|
91
95
|
// app/layout.tsx
|
|
92
|
-
import {
|
|
96
|
+
import { MSALProvider } from '@chemmangat/msal-next';
|
|
93
97
|
|
|
94
98
|
export default function RootLayout({ children }) {
|
|
95
99
|
return (
|
|
96
100
|
<html>
|
|
97
101
|
<body>
|
|
98
|
-
<
|
|
102
|
+
<MSALProvider
|
|
103
|
+
clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
104
|
+
tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
105
|
+
>
|
|
99
106
|
{children}
|
|
100
|
-
</
|
|
107
|
+
</MSALProvider>
|
|
101
108
|
</body>
|
|
102
109
|
</html>
|
|
103
110
|
);
|
|
@@ -127,19 +134,52 @@ That's it! 🎉
|
|
|
127
134
|
|
|
128
135
|
## Components
|
|
129
136
|
|
|
130
|
-
###
|
|
137
|
+
### MSALProvider (Recommended for App Router)
|
|
131
138
|
|
|
132
|
-
|
|
139
|
+
Pre-configured wrapper component that's already marked as `'use client'`. Use this in your server-side layout.tsx.
|
|
133
140
|
|
|
134
141
|
```tsx
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
>
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
// app/layout.tsx (Server Component)
|
|
143
|
+
import { MSALProvider } from '@chemmangat/msal-next';
|
|
144
|
+
|
|
145
|
+
export default function RootLayout({ children }) {
|
|
146
|
+
return (
|
|
147
|
+
<html>
|
|
148
|
+
<body>
|
|
149
|
+
<MSALProvider
|
|
150
|
+
clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
151
|
+
tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
152
|
+
scopes={['User.Read', 'Mail.Read']} // Optional
|
|
153
|
+
enableLogging={true} // Optional
|
|
154
|
+
>
|
|
155
|
+
{children}
|
|
156
|
+
</MSALProvider>
|
|
157
|
+
</body>
|
|
158
|
+
</html>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### MsalAuthProvider (Advanced Usage)
|
|
164
|
+
|
|
165
|
+
The underlying provider component. Only use this if you're creating your own client component wrapper.
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
// app/providers.tsx
|
|
169
|
+
'use client'
|
|
170
|
+
|
|
171
|
+
import { MsalAuthProvider } from '@chemmangat/msal-next';
|
|
172
|
+
|
|
173
|
+
export function MyProviders({ children }) {
|
|
174
|
+
return (
|
|
175
|
+
<MsalAuthProvider
|
|
176
|
+
clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
177
|
+
tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
178
|
+
>
|
|
179
|
+
{children}
|
|
180
|
+
</MsalAuthProvider>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
143
183
|
```
|
|
144
184
|
|
|
145
185
|
### MicrosoftSignInButton
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# Troubleshooting Guide
|
|
2
|
+
|
|
3
|
+
Common issues and their solutions for @chemmangat/msal-next.
|
|
4
|
+
|
|
5
|
+
## "createContext only works in Client Components"
|
|
6
|
+
|
|
7
|
+
### Error Message
|
|
8
|
+
```
|
|
9
|
+
createContext only works in Client Components. Add the "use client" directive at the top of the file to use it.
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Solution
|
|
13
|
+
Use `MSALProvider` instead of `MsalAuthProvider` in your layout.tsx:
|
|
14
|
+
|
|
15
|
+
**❌ Wrong:**
|
|
16
|
+
```tsx
|
|
17
|
+
// app/layout.tsx
|
|
18
|
+
import { MsalAuthProvider } from '@chemmangat/msal-next';
|
|
19
|
+
|
|
20
|
+
export default function RootLayout({ children }) {
|
|
21
|
+
return (
|
|
22
|
+
<html>
|
|
23
|
+
<body>
|
|
24
|
+
<MsalAuthProvider clientId="...">
|
|
25
|
+
{children}
|
|
26
|
+
</MsalAuthProvider>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**✅ Correct:**
|
|
34
|
+
```tsx
|
|
35
|
+
// app/layout.tsx
|
|
36
|
+
import { MSALProvider } from '@chemmangat/msal-next';
|
|
37
|
+
|
|
38
|
+
export default function RootLayout({ children }) {
|
|
39
|
+
return (
|
|
40
|
+
<html>
|
|
41
|
+
<body>
|
|
42
|
+
<MSALProvider
|
|
43
|
+
clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
44
|
+
tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</MSALProvider>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Why?
|
|
55
|
+
- Next.js App Router layouts are Server Components by default
|
|
56
|
+
- `MsalAuthProvider` uses React Context, which requires client-side rendering
|
|
57
|
+
- `MSALProvider` is a pre-configured wrapper that's already marked as `'use client'`
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## "no_token_request_cache_error"
|
|
62
|
+
|
|
63
|
+
### Error Message
|
|
64
|
+
```
|
|
65
|
+
BrowserAuthError: no_token_request_cache_error
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Solution
|
|
69
|
+
This error is now handled automatically in v3.0.2+. If you're still seeing it:
|
|
70
|
+
|
|
71
|
+
1. **Update to the latest version:**
|
|
72
|
+
```bash
|
|
73
|
+
npm install @chemmangat/msal-next@latest
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
2. **Clear your browser cache and cookies** for your app's domain
|
|
77
|
+
|
|
78
|
+
3. **Ensure you're using the correct redirect URI** in Azure AD:
|
|
79
|
+
- Development: `http://localhost:3000`
|
|
80
|
+
- Production: `https://yourdomain.com`
|
|
81
|
+
|
|
82
|
+
### Why?
|
|
83
|
+
This error occurs when:
|
|
84
|
+
- User refreshes the page during authentication flow
|
|
85
|
+
- There's a mismatch between cached auth state and current request
|
|
86
|
+
- The package now handles this gracefully (v3.0.2+)
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## "User cancelled" or Popup Closed
|
|
91
|
+
|
|
92
|
+
### Error Message
|
|
93
|
+
```
|
|
94
|
+
user_cancelled: User cancelled the flow
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Solution
|
|
98
|
+
This is expected behavior when users close the popup. The package handles this gracefully.
|
|
99
|
+
|
|
100
|
+
If you want to show a message to users:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<MicrosoftSignInButton
|
|
104
|
+
onError={(error) => {
|
|
105
|
+
if (error.message.includes('user_cancelled')) {
|
|
106
|
+
console.log('User closed the login popup');
|
|
107
|
+
// Show a friendly message
|
|
108
|
+
}
|
|
109
|
+
}}
|
|
110
|
+
/>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Environment Variables Not Working
|
|
116
|
+
|
|
117
|
+
### Symptoms
|
|
118
|
+
- `undefined` values for clientId or tenantId
|
|
119
|
+
- Authentication not initializing
|
|
120
|
+
|
|
121
|
+
### Solution
|
|
122
|
+
|
|
123
|
+
1. **Check your .env.local file exists:**
|
|
124
|
+
```bash
|
|
125
|
+
# .env.local
|
|
126
|
+
NEXT_PUBLIC_AZURE_AD_CLIENT_ID=your-client-id
|
|
127
|
+
NEXT_PUBLIC_AZURE_AD_TENANT_ID=your-tenant-id
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
2. **Restart your dev server** after adding environment variables:
|
|
131
|
+
```bash
|
|
132
|
+
# Stop the server (Ctrl+C)
|
|
133
|
+
npm run dev
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
3. **Verify the variables are prefixed with `NEXT_PUBLIC_`:**
|
|
137
|
+
- ✅ `NEXT_PUBLIC_AZURE_AD_CLIENT_ID`
|
|
138
|
+
- ❌ `AZURE_AD_CLIENT_ID` (won't work in client components)
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## "Interaction already in progress"
|
|
143
|
+
|
|
144
|
+
### Error Message
|
|
145
|
+
```
|
|
146
|
+
Interaction already in progress
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Solution
|
|
150
|
+
This is a safety feature to prevent multiple concurrent login attempts. Wait for the current interaction to complete.
|
|
151
|
+
|
|
152
|
+
The package automatically prevents this in v3.0.2+, but if you're manually calling login methods:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
const { loginPopup, inProgress } = useMsalAuth();
|
|
156
|
+
|
|
157
|
+
const handleLogin = async () => {
|
|
158
|
+
// Check if interaction is in progress
|
|
159
|
+
if (inProgress) {
|
|
160
|
+
console.log('Please wait for current login to complete');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await loginPopup();
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Token Acquisition Fails
|
|
171
|
+
|
|
172
|
+
### Symptoms
|
|
173
|
+
- `acquireToken()` throws errors
|
|
174
|
+
- Silent token acquisition fails
|
|
175
|
+
|
|
176
|
+
### Solution
|
|
177
|
+
|
|
178
|
+
1. **Ensure user is logged in:**
|
|
179
|
+
```tsx
|
|
180
|
+
const { isAuthenticated, acquireToken } = useMsalAuth();
|
|
181
|
+
|
|
182
|
+
if (!isAuthenticated) {
|
|
183
|
+
// User needs to login first
|
|
184
|
+
await loginPopup();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const token = await acquireToken(['User.Read']);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
2. **Check the scopes are granted in Azure AD:**
|
|
191
|
+
- Go to Azure Portal → App Registrations → Your App → API Permissions
|
|
192
|
+
- Ensure the scopes you're requesting are listed and granted
|
|
193
|
+
|
|
194
|
+
3. **Use the fallback pattern:**
|
|
195
|
+
```tsx
|
|
196
|
+
// acquireToken automatically falls back to popup if silent fails
|
|
197
|
+
const token = await acquireToken(['User.Read']);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## Build Errors with package.json
|
|
203
|
+
|
|
204
|
+
### Error Message
|
|
205
|
+
```
|
|
206
|
+
Error parsing package.json file
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Solution
|
|
210
|
+
This was fixed in v3.0.1. Update to the latest version:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
npm install @chemmangat/msal-next@latest
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
If you're still having issues:
|
|
217
|
+
1. Delete `node_modules` and `package-lock.json`
|
|
218
|
+
2. Run `npm install` again
|
|
219
|
+
3. Clear Next.js cache: `rm -rf .next`
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## TypeScript Errors
|
|
224
|
+
|
|
225
|
+
### Symptoms
|
|
226
|
+
- Type errors with MSAL types
|
|
227
|
+
- Missing type definitions
|
|
228
|
+
|
|
229
|
+
### Solution
|
|
230
|
+
|
|
231
|
+
1. **Ensure peer dependencies are installed:**
|
|
232
|
+
```bash
|
|
233
|
+
npm install @azure/msal-browser@^4.0.0 @azure/msal-react@^3.0.0
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
2. **Check your tsconfig.json includes:**
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"compilerOptions": {
|
|
240
|
+
"moduleResolution": "bundler",
|
|
241
|
+
"jsx": "preserve",
|
|
242
|
+
"lib": ["dom", "dom.iterable", "esnext"]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Still Having Issues?
|
|
250
|
+
|
|
251
|
+
1. **Enable debug logging:**
|
|
252
|
+
```tsx
|
|
253
|
+
<MSALProvider
|
|
254
|
+
clientId="..."
|
|
255
|
+
enableLogging={true}
|
|
256
|
+
>
|
|
257
|
+
{children}
|
|
258
|
+
</MSALProvider>
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
2. **Check the browser console** for detailed error messages
|
|
262
|
+
|
|
263
|
+
3. **Verify Azure AD configuration:**
|
|
264
|
+
- Redirect URIs are correct
|
|
265
|
+
- App is not expired
|
|
266
|
+
- Required permissions are granted
|
|
267
|
+
|
|
268
|
+
4. **Open an issue on GitHub:**
|
|
269
|
+
- Include error messages
|
|
270
|
+
- Include relevant code snippets
|
|
271
|
+
- Include package versions: `npm list @chemmangat/msal-next`
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Common Azure AD Configuration Issues
|
|
276
|
+
|
|
277
|
+
### Redirect URI Mismatch
|
|
278
|
+
- **Error:** `redirect_uri_mismatch`
|
|
279
|
+
- **Solution:** Add your app's URL to Azure AD → App Registrations → Authentication → Redirect URIs
|
|
280
|
+
|
|
281
|
+
### Missing Permissions
|
|
282
|
+
- **Error:** `consent_required` or `invalid_grant`
|
|
283
|
+
- **Solution:** Add required API permissions in Azure AD and grant admin consent if needed
|
|
284
|
+
|
|
285
|
+
### Multi-tenant Issues
|
|
286
|
+
- **Solution:** Use `authorityType: "common"` for multi-tenant apps:
|
|
287
|
+
```tsx
|
|
288
|
+
<MSALProvider
|
|
289
|
+
clientId="..."
|
|
290
|
+
authorityType="common"
|
|
291
|
+
>
|
|
292
|
+
{children}
|
|
293
|
+
</MSALProvider>
|
|
294
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/utils/validation.ts
|
|
2
|
+
function safeJsonParse(jsonString, validator) {
|
|
3
|
+
try {
|
|
4
|
+
const parsed = JSON.parse(jsonString);
|
|
5
|
+
if (validator(parsed)) {
|
|
6
|
+
return parsed;
|
|
7
|
+
}
|
|
8
|
+
console.warn("[Validation] JSON validation failed");
|
|
9
|
+
return null;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("[Validation] JSON parse error:", error);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isValidAccountData(data) {
|
|
16
|
+
return typeof data === "object" && data !== null && typeof data.homeAccountId === "string" && data.homeAccountId.length > 0 && typeof data.username === "string" && data.username.length > 0 && (data.name === void 0 || typeof data.name === "string");
|
|
17
|
+
}
|
|
18
|
+
function sanitizeError(error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
const message = error.message;
|
|
21
|
+
const sanitized = message.replace(/[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g, "[TOKEN_REDACTED]").replace(/[a-f0-9]{32,}/gi, "[SECRET_REDACTED]").replace(/Bearer\s+[^\s]+/gi, "Bearer [REDACTED]");
|
|
22
|
+
return sanitized;
|
|
23
|
+
}
|
|
24
|
+
return "An unexpected error occurred";
|
|
25
|
+
}
|
|
26
|
+
function isValidRedirectUri(uri, allowedOrigins) {
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(uri);
|
|
29
|
+
return allowedOrigins.some((allowed) => {
|
|
30
|
+
const allowedUrl = new URL(allowed);
|
|
31
|
+
return url.origin === allowedUrl.origin;
|
|
32
|
+
});
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isValidScope(scope) {
|
|
38
|
+
return /^[a-zA-Z0-9._-]+$/.test(scope);
|
|
39
|
+
}
|
|
40
|
+
function validateScopes(scopes) {
|
|
41
|
+
return Array.isArray(scopes) && scopes.every(isValidScope);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
safeJsonParse,
|
|
46
|
+
isValidAccountData,
|
|
47
|
+
sanitizeError,
|
|
48
|
+
isValidRedirectUri,
|
|
49
|
+
isValidScope,
|
|
50
|
+
validateScopes
|
|
51
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { Configuration, LogLevel, IPublicClientApplication, PublicClientApplicat
|
|
|
3
3
|
export { AccountInfo } from '@azure/msal-browser';
|
|
4
4
|
import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'react';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
|
+
export { ServerSession } from './server.mjs';
|
|
6
7
|
export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -105,6 +106,34 @@ interface MsalAuthProviderProps extends MsalAuthConfig {
|
|
|
105
106
|
declare function getMsalInstance(): PublicClientApplication | null;
|
|
106
107
|
declare function MsalAuthProvider({ children, loadingComponent, onInitialized, ...config }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
107
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Pre-configured MSALProvider component for Next.js App Router layouts.
|
|
111
|
+
* This component is already marked as 'use client', so you can use it directly
|
|
112
|
+
* in your server-side layout.tsx without needing to create a separate client component.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* // app/layout.tsx
|
|
117
|
+
* import { MSALProvider } from '@chemmangat/msal-next'
|
|
118
|
+
*
|
|
119
|
+
* export default function RootLayout({ children }) {
|
|
120
|
+
* return (
|
|
121
|
+
* <html lang="en">
|
|
122
|
+
* <body>
|
|
123
|
+
* <MSALProvider
|
|
124
|
+
* clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
125
|
+
* tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
126
|
+
* >
|
|
127
|
+
* {children}
|
|
128
|
+
* </MSALProvider>
|
|
129
|
+
* </body>
|
|
130
|
+
* </html>
|
|
131
|
+
* )
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function MSALProvider({ children, ...props }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
136
|
+
|
|
108
137
|
interface MicrosoftSignInButtonProps {
|
|
109
138
|
/**
|
|
110
139
|
* Button text
|
|
@@ -350,34 +379,6 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryS
|
|
|
350
379
|
render(): ReactNode;
|
|
351
380
|
}
|
|
352
381
|
|
|
353
|
-
/**
|
|
354
|
-
* Pre-configured Providers component for Next.js App Router layouts.
|
|
355
|
-
* This component is already marked as 'use client', so you can use it directly
|
|
356
|
-
* in your server-side layout.tsx without needing to create a separate client component.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```tsx
|
|
360
|
-
* // app/layout.tsx
|
|
361
|
-
* import { Providers } from '@chemmangat/msal-next'
|
|
362
|
-
*
|
|
363
|
-
* export default function RootLayout({ children }) {
|
|
364
|
-
* return (
|
|
365
|
-
* <html lang="en">
|
|
366
|
-
* <body>
|
|
367
|
-
* <Providers
|
|
368
|
-
* clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
369
|
-
* tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
370
|
-
* >
|
|
371
|
-
* {children}
|
|
372
|
-
* </Providers>
|
|
373
|
-
* </body>
|
|
374
|
-
* </html>
|
|
375
|
-
* )
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
declare function Providers({ children, ...props }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
380
|
-
|
|
381
382
|
interface UseMsalAuthReturn {
|
|
382
383
|
/**
|
|
383
384
|
* Current authenticated account
|
|
@@ -911,24 +912,4 @@ interface AuthMiddlewareConfig {
|
|
|
911
912
|
*/
|
|
912
913
|
declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
913
914
|
|
|
914
|
-
|
|
915
|
-
/**
|
|
916
|
-
* Whether user is authenticated
|
|
917
|
-
*/
|
|
918
|
-
isAuthenticated: boolean;
|
|
919
|
-
/**
|
|
920
|
-
* User's account ID from MSAL cache
|
|
921
|
-
*/
|
|
922
|
-
accountId?: string;
|
|
923
|
-
/**
|
|
924
|
-
* User's username/email
|
|
925
|
-
*/
|
|
926
|
-
username?: string;
|
|
927
|
-
/**
|
|
928
|
-
* Access token (if available in cookie)
|
|
929
|
-
* @deprecated Storing tokens in cookies is not recommended for security reasons
|
|
930
|
-
*/
|
|
931
|
-
accessToken?: string;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, Providers, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth };
|
|
915
|
+
export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type RetryConfig, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Configuration, LogLevel, IPublicClientApplication, PublicClientApplicat
|
|
|
3
3
|
export { AccountInfo } from '@azure/msal-browser';
|
|
4
4
|
import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'react';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
|
+
export { ServerSession } from './server.js';
|
|
6
7
|
export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -105,6 +106,34 @@ interface MsalAuthProviderProps extends MsalAuthConfig {
|
|
|
105
106
|
declare function getMsalInstance(): PublicClientApplication | null;
|
|
106
107
|
declare function MsalAuthProvider({ children, loadingComponent, onInitialized, ...config }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
107
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Pre-configured MSALProvider component for Next.js App Router layouts.
|
|
111
|
+
* This component is already marked as 'use client', so you can use it directly
|
|
112
|
+
* in your server-side layout.tsx without needing to create a separate client component.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```tsx
|
|
116
|
+
* // app/layout.tsx
|
|
117
|
+
* import { MSALProvider } from '@chemmangat/msal-next'
|
|
118
|
+
*
|
|
119
|
+
* export default function RootLayout({ children }) {
|
|
120
|
+
* return (
|
|
121
|
+
* <html lang="en">
|
|
122
|
+
* <body>
|
|
123
|
+
* <MSALProvider
|
|
124
|
+
* clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
125
|
+
* tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
126
|
+
* >
|
|
127
|
+
* {children}
|
|
128
|
+
* </MSALProvider>
|
|
129
|
+
* </body>
|
|
130
|
+
* </html>
|
|
131
|
+
* )
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function MSALProvider({ children, ...props }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
136
|
+
|
|
108
137
|
interface MicrosoftSignInButtonProps {
|
|
109
138
|
/**
|
|
110
139
|
* Button text
|
|
@@ -350,34 +379,6 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryS
|
|
|
350
379
|
render(): ReactNode;
|
|
351
380
|
}
|
|
352
381
|
|
|
353
|
-
/**
|
|
354
|
-
* Pre-configured Providers component for Next.js App Router layouts.
|
|
355
|
-
* This component is already marked as 'use client', so you can use it directly
|
|
356
|
-
* in your server-side layout.tsx without needing to create a separate client component.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```tsx
|
|
360
|
-
* // app/layout.tsx
|
|
361
|
-
* import { Providers } from '@chemmangat/msal-next'
|
|
362
|
-
*
|
|
363
|
-
* export default function RootLayout({ children }) {
|
|
364
|
-
* return (
|
|
365
|
-
* <html lang="en">
|
|
366
|
-
* <body>
|
|
367
|
-
* <Providers
|
|
368
|
-
* clientId={process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!}
|
|
369
|
-
* tenantId={process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID!}
|
|
370
|
-
* >
|
|
371
|
-
* {children}
|
|
372
|
-
* </Providers>
|
|
373
|
-
* </body>
|
|
374
|
-
* </html>
|
|
375
|
-
* )
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
declare function Providers({ children, ...props }: MsalAuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
380
|
-
|
|
381
382
|
interface UseMsalAuthReturn {
|
|
382
383
|
/**
|
|
383
384
|
* Current authenticated account
|
|
@@ -911,24 +912,4 @@ interface AuthMiddlewareConfig {
|
|
|
911
912
|
*/
|
|
912
913
|
declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
913
914
|
|
|
914
|
-
|
|
915
|
-
/**
|
|
916
|
-
* Whether user is authenticated
|
|
917
|
-
*/
|
|
918
|
-
isAuthenticated: boolean;
|
|
919
|
-
/**
|
|
920
|
-
* User's account ID from MSAL cache
|
|
921
|
-
*/
|
|
922
|
-
accountId?: string;
|
|
923
|
-
/**
|
|
924
|
-
* User's username/email
|
|
925
|
-
*/
|
|
926
|
-
username?: string;
|
|
927
|
-
/**
|
|
928
|
-
* Access token (if available in cookie)
|
|
929
|
-
* @deprecated Storing tokens in cookies is not recommended for security reasons
|
|
930
|
-
*/
|
|
931
|
-
accessToken?: string;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, Providers, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth };
|
|
915
|
+
export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type RetryConfig, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth };
|