@chemmangat/msal-next 4.0.0 → 4.0.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/README.md +102 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,22 +5,74 @@ 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
|
-
> **📦 Current Version:
|
|
8
|
+
> **📦 Current Version: 4.0.1** - Zero-Config Protected Routes! Protect any page with one line of code.
|
|
9
9
|
|
|
10
|
-
>
|
|
10
|
+
> **🚀 What's New:** Export `auth = { required: true }` from any page to protect it. No middleware, no boilerplate!
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## 🚀 What's New in v4.0.1
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
### Zero-Config Protected Routes - THE Killer Feature
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
Protect any route with **one line of code**. No middleware setup, no boilerplate, just export an auth config:
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
// app/dashboard/page.tsx
|
|
20
|
+
export const auth = { required: true };
|
|
21
|
+
|
|
22
|
+
export default function Dashboard() {
|
|
23
|
+
return <div>Protected content - that's it!</div>;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Why This Changes Everything:**
|
|
28
|
+
|
|
29
|
+
| Before (v3.x) | After (v4.0) |
|
|
30
|
+
|---------------|--------------|
|
|
31
|
+
| 50+ lines of middleware | 1 line |
|
|
32
|
+
| Manual redirect logic | Automatic |
|
|
33
|
+
| Boilerplate in every page | Zero boilerplate |
|
|
34
|
+
| 30 min setup | 30 sec setup |
|
|
35
|
+
|
|
36
|
+
### More Examples
|
|
37
|
+
|
|
38
|
+
**Role-Based Access:**
|
|
39
|
+
```tsx
|
|
40
|
+
export const auth = {
|
|
41
|
+
required: true,
|
|
42
|
+
roles: ['admin', 'editor']
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Custom Validation:**
|
|
47
|
+
```tsx
|
|
48
|
+
export const auth = {
|
|
49
|
+
required: true,
|
|
50
|
+
validate: (account) => account.username.endsWith('@company.com')
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Custom UI:**
|
|
55
|
+
```tsx
|
|
56
|
+
export const auth = {
|
|
57
|
+
required: true,
|
|
58
|
+
loading: <Spinner />,
|
|
59
|
+
unauthorized: <AccessDenied />
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Features (v4.0.1)
|
|
66
|
+
|
|
67
|
+
✨ **Zero-Config Protection** - One line to protect any route
|
|
68
|
+
🎯 **Role-Based Access** - Built-in Azure AD role checking
|
|
69
|
+
🔐 **Custom Validation** - Add your own auth logic
|
|
70
|
+
⚡ **Automatic Redirects** - Smart return URL handling
|
|
71
|
+
🎨 **Custom UI** - Override loading/unauthorized states
|
|
72
|
+
📦 **TypeScript First** - Full type safety
|
|
73
|
+
🚀 **Next.js 14+** - Built for App Router
|
|
74
|
+
|
|
75
|
+
---
|
|
24
76
|
|
|
25
77
|
## What's New in v3.0
|
|
26
78
|
|
|
@@ -626,6 +678,44 @@ Enable debug logging to troubleshoot issues:
|
|
|
626
678
|
</MsalAuthProvider>
|
|
627
679
|
```
|
|
628
680
|
|
|
681
|
+
## Migration to v4.0.1
|
|
682
|
+
|
|
683
|
+
### From v3.x to v4.0.1
|
|
684
|
+
|
|
685
|
+
**Good news:** v4.0.0 is **100% backward compatible**! All v3.x code works without changes.
|
|
686
|
+
|
|
687
|
+
**New feature:** Zero-Config Protected Routes (optional, but recommended)
|
|
688
|
+
|
|
689
|
+
**Before (v3.x - still works):**
|
|
690
|
+
```tsx
|
|
691
|
+
// middleware.ts
|
|
692
|
+
export async function middleware(request) {
|
|
693
|
+
const session = await getServerSession();
|
|
694
|
+
if (!session) return redirect('/login');
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// app/dashboard/page.tsx
|
|
698
|
+
export default async function Dashboard() {
|
|
699
|
+
const session = await getServerSession();
|
|
700
|
+
if (!session) redirect('/login');
|
|
701
|
+
return <div>Protected</div>;
|
|
702
|
+
}
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
**After (v4.0 - recommended):**
|
|
706
|
+
```tsx
|
|
707
|
+
// app/dashboard/page.tsx
|
|
708
|
+
export const auth = { required: true };
|
|
709
|
+
|
|
710
|
+
export default function Dashboard() {
|
|
711
|
+
return <div>Protected</div>;
|
|
712
|
+
}
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
**That's it!** No breaking changes, just a better way to protect routes.
|
|
716
|
+
|
|
717
|
+
---
|
|
718
|
+
|
|
629
719
|
## Migration Guide
|
|
630
720
|
|
|
631
721
|
### From v2.x to v3.0
|
package/package.json
CHANGED