nextauthz 1.3.20 → 1.3.22

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/dist/index.js CHANGED
@@ -46,11 +46,12 @@ var useAuthStore = (0, import_zustand.create)((set) => ({
46
46
  setAuthChecked: (checked) => set({ isAuthChecked: checked }),
47
47
  setLoading: (loading) => set({ loading }),
48
48
  setError: (err) => set({ error: err }),
49
- resetAuth: () => set({
49
+ resetAuth: (logout = false) => set({
50
50
  user: null,
51
51
  role: null,
52
52
  isAuthenticated: false,
53
- isAuthChecked: false,
53
+ isAuthChecked: logout ? true : false,
54
+ // ✅ true if logout, false if initial load failed
54
55
  loading: false,
55
56
  error: null
56
57
  })
@@ -160,7 +161,10 @@ var AuthGuard = ({
160
161
  }
161
162
  }, [isAuthenticated, isAuthChecked, redirectTo, router]);
162
163
  if (!isAuthChecked) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: fallback });
163
- if (!isAuthenticated) return null;
164
+ if (!isAuthenticated) {
165
+ router.replace(redirectTo);
166
+ return null;
167
+ }
164
168
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
165
169
  };
166
170
  var AuthGuard_default = AuthGuard;
@@ -176,7 +180,7 @@ var RoleGuard = ({
176
180
  fallback = null
177
181
  }) => {
178
182
  const router = (0, import_navigation2.useRouter)();
179
- const { role, isAuthChecked } = useAuthStore();
183
+ const { role, isAuthChecked, isAuthenticated } = useAuthStore();
180
184
  (0, import_react3.useEffect)(() => {
181
185
  if (!isAuthChecked) return;
182
186
  if (!role || !allowedRoles.includes(role)) {
@@ -184,6 +188,10 @@ var RoleGuard = ({
184
188
  }
185
189
  }, [role, isAuthChecked, allowedRoles, redirectTo, router]);
186
190
  if (!isAuthChecked) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: fallback });
191
+ if (!isAuthenticated) {
192
+ router.replace(redirectTo);
193
+ return null;
194
+ }
187
195
  if (!role || !allowedRoles.includes(role)) return null;
188
196
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
189
197
  };
package/dist/index.mjs CHANGED
@@ -19,11 +19,12 @@ var useAuthStore = create((set) => ({
19
19
  setAuthChecked: (checked) => set({ isAuthChecked: checked }),
20
20
  setLoading: (loading) => set({ loading }),
21
21
  setError: (err) => set({ error: err }),
22
- resetAuth: () => set({
22
+ resetAuth: (logout = false) => set({
23
23
  user: null,
24
24
  role: null,
25
25
  isAuthenticated: false,
26
- isAuthChecked: false,
26
+ isAuthChecked: logout ? true : false,
27
+ // ✅ true if logout, false if initial load failed
27
28
  loading: false,
28
29
  error: null
29
30
  })
@@ -133,7 +134,10 @@ var AuthGuard = ({
133
134
  }
134
135
  }, [isAuthenticated, isAuthChecked, redirectTo, router]);
135
136
  if (!isAuthChecked) return /* @__PURE__ */ jsx2(Fragment, { children: fallback });
136
- if (!isAuthenticated) return null;
137
+ if (!isAuthenticated) {
138
+ router.replace(redirectTo);
139
+ return null;
140
+ }
137
141
  return /* @__PURE__ */ jsx2(Fragment, { children });
138
142
  };
139
143
  var AuthGuard_default = AuthGuard;
@@ -149,7 +153,7 @@ var RoleGuard = ({
149
153
  fallback = null
150
154
  }) => {
151
155
  const router = useRouter2();
152
- const { role, isAuthChecked } = useAuthStore();
156
+ const { role, isAuthChecked, isAuthenticated } = useAuthStore();
153
157
  useEffect3(() => {
154
158
  if (!isAuthChecked) return;
155
159
  if (!role || !allowedRoles.includes(role)) {
@@ -157,6 +161,10 @@ var RoleGuard = ({
157
161
  }
158
162
  }, [role, isAuthChecked, allowedRoles, redirectTo, router]);
159
163
  if (!isAuthChecked) return /* @__PURE__ */ jsx3(Fragment2, { children: fallback });
164
+ if (!isAuthenticated) {
165
+ router.replace(redirectTo);
166
+ return null;
167
+ }
160
168
  if (!role || !allowedRoles.includes(role)) return null;
161
169
  return /* @__PURE__ */ jsx3(Fragment2, { children });
162
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextauthz",
3
- "version": "1.3.20",
3
+ "version": "1.3.22",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/AuthGuard.tsx CHANGED
@@ -29,7 +29,11 @@ const AuthGuard = ({
29
29
 
30
30
  if (!isAuthChecked) return <>{fallback}</>
31
31
 
32
- if (!isAuthenticated) return null
32
+ if (!isAuthenticated) {
33
+ router.replace(redirectTo)
34
+ return null
35
+ }
36
+
33
37
 
34
38
  return <>{children}</>
35
39
  }
package/src/RoleGuard.tsx CHANGED
@@ -18,7 +18,7 @@ const RoleGuard = ({
18
18
  fallback = null,
19
19
  }: RoleGuardProps) => {
20
20
  const router = useRouter()
21
- const { role, isAuthChecked } = useAuthStore()
21
+ const { role, isAuthChecked, isAuthenticated } = useAuthStore()
22
22
 
23
23
  useEffect(() => {
24
24
  if (!isAuthChecked) return
@@ -29,9 +29,14 @@ const RoleGuard = ({
29
29
  }
30
30
  }, [role, isAuthChecked, allowedRoles, redirectTo, router])
31
31
 
32
- // Show fallback while loading
33
32
  if (!isAuthChecked) return <>{fallback}</>
34
33
 
34
+ if (!isAuthenticated) {
35
+ router.replace(redirectTo)
36
+ return null
37
+ }
38
+
39
+
35
40
  // Block rendering if role is not allowed
36
41
  if (!role || !allowedRoles.includes(role)) return null
37
42
 
@@ -41,13 +41,13 @@ export const useAuthStore = create<AuthState>((set) => ({
41
41
  setLoading: (loading) => set({ loading }),
42
42
  setError: (err) => set({ error: err }),
43
43
 
44
- resetAuth: () =>
44
+ resetAuth: (logout = false) =>
45
45
  set({
46
46
  user: null,
47
47
  role: null,
48
48
  isAuthenticated: false,
49
- isAuthChecked: false,
49
+ isAuthChecked: logout ? true : false, // ✅ true if logout, false if initial load failed
50
50
  loading: false,
51
51
  error: null,
52
- }),
52
+ }),
53
53
  }))