nextauthz 1.0.0
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 +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +1986 -0
- package/dist/index.mjs +1969 -0
- package/package.json +26 -0
- package/readme.md +180 -0
- package/src/AuthGuard.tsx +67 -0
- package/src/AuthProvider.tsx +89 -0
- package/src/RoleGuard.tsx +37 -0
- package/src/index.ts +16 -0
- package/src/myAuth.ts +7 -0
- package/store/useGuardStore.ts +39 -0
- package/tsconfig.json +13 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default, { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type AuthContextType<UserType> = {
|
|
6
|
+
user: UserType | any;
|
|
7
|
+
login: (tokens: Record<string, string>, user: UserType) => void;
|
|
8
|
+
logout: () => void;
|
|
9
|
+
setUser: (user: UserType) => void;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
};
|
|
13
|
+
type AuthContextOptions = {
|
|
14
|
+
storage?: 'localStorage' | 'sessionStorage' | 'cookie';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Factory to create typed AuthProvider and 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
|
+
|
|
26
|
+
type AuthGuardProps = {
|
|
27
|
+
children: React__default.ReactNode;
|
|
28
|
+
redirectTo?: string;
|
|
29
|
+
tokenKey?: string;
|
|
30
|
+
refreshToken?: () => Promise<string | null>;
|
|
31
|
+
};
|
|
32
|
+
declare const AuthGuard: ({ children, redirectTo, tokenKey, refreshToken, }: AuthGuardProps) => react_jsx_runtime.JSX.Element | null;
|
|
33
|
+
|
|
34
|
+
type RoleGuardProps = {
|
|
35
|
+
children: React__default.ReactNode;
|
|
36
|
+
allowedRoles: string[];
|
|
37
|
+
redirectTo?: string;
|
|
38
|
+
};
|
|
39
|
+
declare const RoleGuard: ({ children, allowedRoles, redirectTo, }: RoleGuardProps) => react_jsx_runtime.JSX.Element;
|
|
40
|
+
|
|
41
|
+
type User = {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
declare function createAppAuth(storage?: 'localStorage' | 'sessionStorage' | 'cookie'): {
|
|
45
|
+
AuthProvider: ({ children }: {
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
48
|
+
useAuth: () => AuthContextType<User>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { AuthGuard, RoleGuard, type User, createAppAuth, createAuthContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default, { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type AuthContextType<UserType> = {
|
|
6
|
+
user: UserType | any;
|
|
7
|
+
login: (tokens: Record<string, string>, user: UserType) => void;
|
|
8
|
+
logout: () => void;
|
|
9
|
+
setUser: (user: UserType) => void;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
};
|
|
13
|
+
type AuthContextOptions = {
|
|
14
|
+
storage?: 'localStorage' | 'sessionStorage' | 'cookie';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Factory to create typed AuthProvider and 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
|
+
|
|
26
|
+
type AuthGuardProps = {
|
|
27
|
+
children: React__default.ReactNode;
|
|
28
|
+
redirectTo?: string;
|
|
29
|
+
tokenKey?: string;
|
|
30
|
+
refreshToken?: () => Promise<string | null>;
|
|
31
|
+
};
|
|
32
|
+
declare const AuthGuard: ({ children, redirectTo, tokenKey, refreshToken, }: AuthGuardProps) => react_jsx_runtime.JSX.Element | null;
|
|
33
|
+
|
|
34
|
+
type RoleGuardProps = {
|
|
35
|
+
children: React__default.ReactNode;
|
|
36
|
+
allowedRoles: string[];
|
|
37
|
+
redirectTo?: string;
|
|
38
|
+
};
|
|
39
|
+
declare const RoleGuard: ({ children, allowedRoles, redirectTo, }: RoleGuardProps) => react_jsx_runtime.JSX.Element;
|
|
40
|
+
|
|
41
|
+
type User = {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
declare function createAppAuth(storage?: 'localStorage' | 'sessionStorage' | 'cookie'): {
|
|
45
|
+
AuthProvider: ({ children }: {
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
48
|
+
useAuth: () => AuthContextType<User>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { AuthGuard, RoleGuard, type User, createAppAuth, createAuthContext };
|