nextauthz 1.1.8 → 1.1.9

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.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { ReactNode } from 'react';
3
+ import React__default from 'react';
4
4
 
5
5
  type AuthContextType<UserType> = {
6
6
  user: UserType | null;
@@ -10,18 +10,6 @@ type AuthContextType<UserType> = {
10
10
  loading: boolean;
11
11
  error: Error | null;
12
12
  };
13
- type AuthContextOptions = {
14
- storage?: 'localStorage' | 'sessionStorage' | 'cookie';
15
- };
16
- /**
17
- * Factory to create AuthProvider and typed useAuth hook
18
- */
19
- declare function createAuthContext<UserType>(options?: AuthContextOptions): {
20
- AuthProvider: ({ children }: {
21
- children: ReactNode;
22
- }) => react_jsx_runtime.JSX.Element;
23
- useAuth: () => AuthContextType<UserType>;
24
- };
25
13
 
26
14
  type AuthGuardProps = {
27
15
  children: React__default.ReactNode;
@@ -36,16 +24,18 @@ type RoleGuardProps = {
36
24
  allowedRoles: string[];
37
25
  redirectTo?: string;
38
26
  };
39
- declare const RoleGuard: React__default.FC<RoleGuardProps>;
27
+ declare const RoleGuard: ({ children, allowedRoles, redirectTo, }: RoleGuardProps) => react_jsx_runtime.JSX.Element;
40
28
 
41
- type User = {
42
- [key: string]: any;
43
- };
29
+ type User = any;
44
30
  declare function createAppAuth(storage?: 'localStorage' | 'sessionStorage' | 'cookie'): {
45
31
  AuthProvider: ({ children }: {
46
32
  children: React.ReactNode;
47
33
  }) => react_jsx_runtime.JSX.Element;
48
- useAuth: () => AuthContextType<User>;
34
+ useAuth: () => AuthContextType<any>;
49
35
  };
36
+ declare const AuthProvider: ({ children }: {
37
+ children: React.ReactNode;
38
+ }) => react_jsx_runtime.JSX.Element;
39
+ declare const useAuth: () => AuthContextType<any>;
50
40
 
51
- export { AuthGuard, RoleGuard, type User, createAppAuth, createAuthContext };
41
+ export { AuthGuard, AuthProvider, RoleGuard, type User, createAppAuth, useAuth };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { ReactNode } from 'react';
3
+ import React__default from 'react';
4
4
 
5
5
  type AuthContextType<UserType> = {
6
6
  user: UserType | null;
@@ -10,18 +10,6 @@ type AuthContextType<UserType> = {
10
10
  loading: boolean;
11
11
  error: Error | null;
12
12
  };
13
- type AuthContextOptions = {
14
- storage?: 'localStorage' | 'sessionStorage' | 'cookie';
15
- };
16
- /**
17
- * Factory to create AuthProvider and typed useAuth hook
18
- */
19
- declare function createAuthContext<UserType>(options?: AuthContextOptions): {
20
- AuthProvider: ({ children }: {
21
- children: ReactNode;
22
- }) => react_jsx_runtime.JSX.Element;
23
- useAuth: () => AuthContextType<UserType>;
24
- };
25
13
 
26
14
  type AuthGuardProps = {
27
15
  children: React__default.ReactNode;
@@ -36,16 +24,18 @@ type RoleGuardProps = {
36
24
  allowedRoles: string[];
37
25
  redirectTo?: string;
38
26
  };
39
- declare const RoleGuard: React__default.FC<RoleGuardProps>;
27
+ declare const RoleGuard: ({ children, allowedRoles, redirectTo, }: RoleGuardProps) => react_jsx_runtime.JSX.Element;
40
28
 
41
- type User = {
42
- [key: string]: any;
43
- };
29
+ type User = any;
44
30
  declare function createAppAuth(storage?: 'localStorage' | 'sessionStorage' | 'cookie'): {
45
31
  AuthProvider: ({ children }: {
46
32
  children: React.ReactNode;
47
33
  }) => react_jsx_runtime.JSX.Element;
48
- useAuth: () => AuthContextType<User>;
34
+ useAuth: () => AuthContextType<any>;
49
35
  };
36
+ declare const AuthProvider: ({ children }: {
37
+ children: React.ReactNode;
38
+ }) => react_jsx_runtime.JSX.Element;
39
+ declare const useAuth: () => AuthContextType<any>;
50
40
 
51
- export { AuthGuard, RoleGuard, type User, createAppAuth, createAuthContext };
41
+ export { AuthGuard, AuthProvider, RoleGuard, type User, createAppAuth, useAuth };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ "use client";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -21,9 +22,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
22
  var index_exports = {};
22
23
  __export(index_exports, {
23
24
  AuthGuard: () => AuthGuard_default,
25
+ AuthProvider: () => AuthProvider,
24
26
  RoleGuard: () => RoleGuard_default,
25
27
  createAppAuth: () => createAppAuth,
26
- createAuthContext: () => createAuthContext
28
+ useAuth: () => useAuth
27
29
  });
28
30
  module.exports = __toCommonJS(index_exports);
29
31
 
@@ -54,7 +56,7 @@ var useAuthStore = (0, import_zustand.create)((set) => ({
54
56
  var import_jsx_runtime = require("react/jsx-runtime");
55
57
  function createAuthContext(options) {
56
58
  const AuthContext = (0, import_react.createContext)(null);
57
- const AuthProvider = ({ children }) => {
59
+ const AuthProvider2 = ({ children }) => {
58
60
  const storageType = options?.storage || "cookie";
59
61
  (0, import_react.useEffect)(() => {
60
62
  (0, import_react_token_manager.configureTokenManager)({ storage: storageType });
@@ -113,12 +115,12 @@ function createAuthContext(options) {
113
115
  }
114
116
  );
115
117
  };
116
- const useAuth = () => {
118
+ const useAuth2 = () => {
117
119
  const ctx = (0, import_react.useContext)(AuthContext);
118
120
  if (!ctx) throw new Error("useAuth must be used inside AuthProvider");
119
121
  return ctx;
120
122
  };
121
- return { AuthProvider, useAuth };
123
+ return { AuthProvider: AuthProvider2, useAuth: useAuth2 };
122
124
  }
123
125
 
124
126
  // src/AuthGuard.tsx
@@ -178,18 +180,12 @@ var AuthGuard_default = AuthGuard;
178
180
  // src/RoleGuard.tsx
179
181
  var import_react3 = require("react");
180
182
  var import_navigation2 = require("next/navigation");
181
-
182
- // src/myAuth.ts
183
- var auth = createAppAuth();
184
-
185
- // src/RoleGuard.tsx
186
183
  var import_jsx_runtime3 = require("react/jsx-runtime");
187
184
  var RoleGuard = ({
188
185
  children,
189
186
  allowedRoles,
190
187
  redirectTo = "/unauthorized"
191
188
  }) => {
192
- const { useAuth } = auth;
193
189
  const { user, loading } = useAuth();
194
190
  const router = (0, import_navigation2.useRouter)();
195
191
  const [isChecking, setIsChecking] = (0, import_react3.useState)(true);
@@ -210,10 +206,12 @@ var RoleGuard_default = RoleGuard;
210
206
  function createAppAuth(storage = "cookie") {
211
207
  return createAuthContext({ storage });
212
208
  }
209
+ var { AuthProvider, useAuth } = createAppAuth();
213
210
  // Annotate the CommonJS export names for ESM import in node:
214
211
  0 && (module.exports = {
215
212
  AuthGuard,
213
+ AuthProvider,
216
214
  RoleGuard,
217
215
  createAppAuth,
218
- createAuthContext
216
+ useAuth
219
217
  });
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  // src/AuthProvider.tsx
2
4
  import {
3
5
  createContext,
@@ -30,7 +32,7 @@ var useAuthStore = create((set) => ({
30
32
  import { jsx } from "react/jsx-runtime";
31
33
  function createAuthContext(options) {
32
34
  const AuthContext = createContext(null);
33
- const AuthProvider = ({ children }) => {
35
+ const AuthProvider2 = ({ children }) => {
34
36
  const storageType = options?.storage || "cookie";
35
37
  useEffect(() => {
36
38
  configureTokenManager({ storage: storageType });
@@ -89,12 +91,12 @@ function createAuthContext(options) {
89
91
  }
90
92
  );
91
93
  };
92
- const useAuth = () => {
94
+ const useAuth2 = () => {
93
95
  const ctx = useContext(AuthContext);
94
96
  if (!ctx) throw new Error("useAuth must be used inside AuthProvider");
95
97
  return ctx;
96
98
  };
97
- return { AuthProvider, useAuth };
99
+ return { AuthProvider: AuthProvider2, useAuth: useAuth2 };
98
100
  }
99
101
 
100
102
  // src/AuthGuard.tsx
@@ -154,18 +156,12 @@ var AuthGuard_default = AuthGuard;
154
156
  // src/RoleGuard.tsx
155
157
  import { useEffect as useEffect3, useState as useState3 } from "react";
156
158
  import { useRouter as useRouter2 } from "next/navigation";
157
-
158
- // src/myAuth.ts
159
- var auth = createAppAuth();
160
-
161
- // src/RoleGuard.tsx
162
159
  import { Fragment as Fragment2, jsx as jsx3 } from "react/jsx-runtime";
163
160
  var RoleGuard = ({
164
161
  children,
165
162
  allowedRoles,
166
163
  redirectTo = "/unauthorized"
167
164
  }) => {
168
- const { useAuth } = auth;
169
165
  const { user, loading } = useAuth();
170
166
  const router = useRouter2();
171
167
  const [isChecking, setIsChecking] = useState3(true);
@@ -186,9 +182,11 @@ var RoleGuard_default = RoleGuard;
186
182
  function createAppAuth(storage = "cookie") {
187
183
  return createAuthContext({ storage });
188
184
  }
185
+ var { AuthProvider, useAuth } = createAppAuth();
189
186
  export {
190
187
  AuthGuard_default as AuthGuard,
188
+ AuthProvider,
191
189
  RoleGuard_default as RoleGuard,
192
190
  createAppAuth,
193
- createAuthContext
191
+ useAuth
194
192
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextauthz",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/RoleGuard.tsx CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import React, { useEffect, useState } from 'react'
4
4
  import { useRouter } from 'next/navigation'
5
- import { auth } from './myAuth'
5
+ import { useAuth } from '.'
6
6
 
7
7
  type RoleGuardProps = {
8
8
  children: React.ReactNode
@@ -10,15 +10,12 @@ type RoleGuardProps = {
10
10
  redirectTo?: string
11
11
  }
12
12
 
13
- const RoleGuard: React.FC<RoleGuardProps> = ({
13
+ const RoleGuard = ({
14
14
  children,
15
15
  allowedRoles,
16
16
  redirectTo = '/unauthorized',
17
- }) => {
18
- // ✅ Destructure useAuth INSIDE the component
19
- const { useAuth } = auth
17
+ }: RoleGuardProps) => {
20
18
  const { user, loading } = useAuth()
21
-
22
19
  const router = useRouter()
23
20
  const [isChecking, setIsChecking] = useState(true)
24
21
 
package/src/index.ts CHANGED
@@ -1,16 +1,18 @@
1
+ // src/index.ts
2
+ 'use client'
3
+
1
4
  import { createAuthContext } from './AuthProvider'
5
+ export { default as AuthGuard } from './AuthGuard'
6
+ export { default as RoleGuard } from './RoleGuard'
2
7
 
3
- export type User = {
4
- [key: string]: any
5
- }
8
+ export type User = any
6
9
 
7
- // Export factory instead of fixed instance
10
+ // Factory function for app
8
11
  export function createAppAuth(
9
12
  storage: 'localStorage' | 'sessionStorage' | 'cookie' = 'cookie'
10
13
  ) {
11
14
  return createAuthContext<User>({ storage })
12
15
  }
13
16
 
14
- export { createAuthContext } from './AuthProvider'
15
- export { default as AuthGuard } from './AuthGuard'
16
- export { default as RoleGuard } from './RoleGuard'
17
+ // Default instance (optional)
18
+ export const { AuthProvider, useAuth } = createAppAuth()
package/src/myAuth.ts DELETED
@@ -1,4 +0,0 @@
1
- // myAuth.ts
2
- 'use client'
3
- import { createAppAuth } from '.'
4
- export const auth = createAppAuth() // { AuthProvider, useAuth }