nextauthz 1.3.27 → 1.3.29

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,12 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as React from 'react';
3
- import React__default from 'react';
2
+ import React, { ReactNode } from 'react';
4
3
 
5
- type User$1 = {
4
+ type User = {
6
5
  [key: string]: any;
7
6
  };
8
7
 
9
- type AuthContextType<UserType extends User$1 = User$1> = {
8
+ type AuthContextType<UserType extends User = User> = {
10
9
  user: UserType | null;
11
10
  role: string | null;
12
11
  isAuthenticated: boolean;
@@ -16,32 +15,31 @@ type AuthContextType<UserType extends User$1 = User$1> = {
16
15
  setUser: (user: UserType | null) => void;
17
16
  tokenKey: string;
18
17
  };
18
+ declare function createAuthContext<UserType extends User = User>(option?: {
19
+ storage?: 'localStorage' | 'sessionStorage' | 'cookie';
20
+ tokenKey?: string;
21
+ rolePath?: string;
22
+ }): {
23
+ AuthProvider: ({ children }: {
24
+ children: ReactNode;
25
+ }) => react_jsx_runtime.JSX.Element;
26
+ useAuth: () => AuthContextType<UserType>;
27
+ tokenKey: string;
28
+ };
19
29
 
20
30
  type AuthGuardProps = {
21
- children: React__default.ReactNode;
31
+ children: React.ReactNode;
22
32
  redirectTo?: string;
23
- fallback?: React__default.ReactNode;
33
+ fallback?: React.ReactNode;
24
34
  };
25
35
  declare const AuthGuard: ({ children, redirectTo, fallback, }: AuthGuardProps) => react_jsx_runtime.JSX.Element | null;
26
36
 
27
37
  type RoleGuardProps = {
28
- children: React__default.ReactNode;
38
+ children: React.ReactNode;
29
39
  allowedRoles: string[];
30
40
  redirectTo?: string;
31
- fallback?: React__default.ReactNode;
41
+ fallback?: React.ReactNode;
32
42
  };
33
43
  declare const RoleGuard: ({ children, allowedRoles, redirectTo, fallback, }: RoleGuardProps) => react_jsx_runtime.JSX.Element | null;
34
44
 
35
- type User = Record<string, any>;
36
- /**
37
- * Factory to create isolated auth instance
38
- */
39
- declare function createAppAuth(storage: 'localStorage' | 'sessionStorage' | 'cookie', tokenKey?: string): {
40
- AuthProvider: ({ children }: {
41
- children: React.ReactNode;
42
- }) => react_jsx_runtime.JSX.Element;
43
- useAuth: () => AuthContextType<User$1>;
44
- tokenKey: string;
45
- };
46
-
47
- export { AuthGuard, RoleGuard, type User, createAppAuth };
45
+ export { AuthGuard, RoleGuard, createAuthContext };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as React from 'react';
3
- import React__default from 'react';
2
+ import React, { ReactNode } from 'react';
4
3
 
5
- type User$1 = {
4
+ type User = {
6
5
  [key: string]: any;
7
6
  };
8
7
 
9
- type AuthContextType<UserType extends User$1 = User$1> = {
8
+ type AuthContextType<UserType extends User = User> = {
10
9
  user: UserType | null;
11
10
  role: string | null;
12
11
  isAuthenticated: boolean;
@@ -16,32 +15,31 @@ type AuthContextType<UserType extends User$1 = User$1> = {
16
15
  setUser: (user: UserType | null) => void;
17
16
  tokenKey: string;
18
17
  };
18
+ declare function createAuthContext<UserType extends User = User>(option?: {
19
+ storage?: 'localStorage' | 'sessionStorage' | 'cookie';
20
+ tokenKey?: string;
21
+ rolePath?: string;
22
+ }): {
23
+ AuthProvider: ({ children }: {
24
+ children: ReactNode;
25
+ }) => react_jsx_runtime.JSX.Element;
26
+ useAuth: () => AuthContextType<UserType>;
27
+ tokenKey: string;
28
+ };
19
29
 
20
30
  type AuthGuardProps = {
21
- children: React__default.ReactNode;
31
+ children: React.ReactNode;
22
32
  redirectTo?: string;
23
- fallback?: React__default.ReactNode;
33
+ fallback?: React.ReactNode;
24
34
  };
25
35
  declare const AuthGuard: ({ children, redirectTo, fallback, }: AuthGuardProps) => react_jsx_runtime.JSX.Element | null;
26
36
 
27
37
  type RoleGuardProps = {
28
- children: React__default.ReactNode;
38
+ children: React.ReactNode;
29
39
  allowedRoles: string[];
30
40
  redirectTo?: string;
31
- fallback?: React__default.ReactNode;
41
+ fallback?: React.ReactNode;
32
42
  };
33
43
  declare const RoleGuard: ({ children, allowedRoles, redirectTo, fallback, }: RoleGuardProps) => react_jsx_runtime.JSX.Element | null;
34
44
 
35
- type User = Record<string, any>;
36
- /**
37
- * Factory to create isolated auth instance
38
- */
39
- declare function createAppAuth(storage: 'localStorage' | 'sessionStorage' | 'cookie', tokenKey?: string): {
40
- AuthProvider: ({ children }: {
41
- children: React.ReactNode;
42
- }) => react_jsx_runtime.JSX.Element;
43
- useAuth: () => AuthContextType<User$1>;
44
- tokenKey: string;
45
- };
46
-
47
- export { AuthGuard, RoleGuard, type User, createAppAuth };
45
+ export { AuthGuard, RoleGuard, createAuthContext };
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var index_exports = {};
23
23
  __export(index_exports, {
24
24
  AuthGuard: () => AuthGuard_default,
25
25
  RoleGuard: () => RoleGuard_default,
26
- createAppAuth: () => createAppAuth
26
+ createAuthContext: () => createAuthContext
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
 
@@ -84,6 +84,7 @@ function createAuthContext(option) {
84
84
  if (!userObj || !rolePath) return null;
85
85
  return rolePath.split(".").reduce((acc, key) => acc?.[key], userObj) ?? null;
86
86
  };
87
+ console.log("extractRole", extractRole);
87
88
  (0, import_react.useEffect)(() => {
88
89
  const storedUser = manager.getSingleToken("user");
89
90
  const token = manager.getSingleToken(tokenKey);
@@ -201,14 +202,9 @@ var RoleGuard = ({
201
202
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
202
203
  };
203
204
  var RoleGuard_default = RoleGuard;
204
-
205
- // src/index.ts
206
- function createAppAuth(storage, tokenKey = "access_token") {
207
- return createAuthContext({ storage, tokenKey });
208
- }
209
205
  // Annotate the CommonJS export names for ESM import in node:
210
206
  0 && (module.exports = {
211
207
  AuthGuard,
212
208
  RoleGuard,
213
- createAppAuth
209
+ createAuthContext
214
210
  });
package/dist/index.mjs CHANGED
@@ -57,6 +57,7 @@ function createAuthContext(option) {
57
57
  if (!userObj || !rolePath) return null;
58
58
  return rolePath.split(".").reduce((acc, key) => acc?.[key], userObj) ?? null;
59
59
  };
60
+ console.log("extractRole", extractRole);
60
61
  useEffect(() => {
61
62
  const storedUser = manager.getSingleToken("user");
62
63
  const token = manager.getSingleToken(tokenKey);
@@ -174,13 +175,8 @@ var RoleGuard = ({
174
175
  return /* @__PURE__ */ jsx3(Fragment2, { children });
175
176
  };
176
177
  var RoleGuard_default = RoleGuard;
177
-
178
- // src/index.ts
179
- function createAppAuth(storage, tokenKey = "access_token") {
180
- return createAuthContext({ storage, tokenKey });
181
- }
182
178
  export {
183
179
  AuthGuard_default as AuthGuard,
184
180
  RoleGuard_default as RoleGuard,
185
- createAppAuth
181
+ createAuthContext
186
182
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextauthz",
3
- "version": "1.3.27",
3
+ "version": "1.3.29",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -60,6 +60,9 @@ export function createAuthContext<UserType extends User = User>(option?: {
60
60
  return rolePath.split('.').reduce((acc: any, key: string) => acc?.[key], userObj) ?? null
61
61
  }
62
62
 
63
+ console.log('extractRole', extractRole);
64
+
65
+
63
66
  /* ---------------------------------- */
64
67
  /* Hydrate user from storage */
65
68
  /* ---------------------------------- */
package/src/index.ts CHANGED
@@ -1,18 +1,7 @@
1
1
  'use client'
2
2
 
3
- import { createAuthContext } from './AuthProvider'
3
+ export { createAuthContext } from './AuthProvider'
4
4
 
5
5
  export { default as AuthGuard } from './AuthGuard'
6
6
  export { default as RoleGuard } from './RoleGuard'
7
7
 
8
- export type User = Record<string, any>
9
-
10
- /**
11
- * Factory to create isolated auth instance
12
- */
13
- export function createAppAuth(
14
- storage: 'localStorage' | 'sessionStorage' | 'cookie',
15
- tokenKey: string = 'access_token' // <-- default token key
16
- ) {
17
- return createAuthContext({ storage, tokenKey })
18
- }