@purr-core/components.authenticator 0.0.10 → 0.0.11
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.cjs +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var o=require('react'),reactRouterDom=require('react-router-dom'),N=require('@purr-core/hooks.block');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var o__default=/*#__PURE__*/_interopDefault(o);var N__default=/*#__PURE__*/_interopDefault(N);var e={HOME:"/",NOT_FOUND:"*",LOGIN:"/login"};var x=({children:f,isAuthenticated:i=false,extendRoutes:s,routeToGoWhenUnauthenticated:m,routeToGoWhenAuthenticated:n})=>{let p=reactRouterDom.useLocation(),r=N__default.default(()=>({...e,...s}));return i&&p.pathname===r.LOGIN?n?o__default.default.createElement(reactRouterDom.Navigate,{to:n}):o__default.default.createElement(reactRouterDom.Navigate,{to:r.HOME}):!i&&p.pathname!==r.LOGIN?m?o__default.default.createElement(reactRouterDom.Navigate,{to:m}):o__default.default.createElement(reactRouterDom.Navigate,{to:r.LOGIN}):f};exports.Authenticator=x;exports.BASE_ROUTES=e;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The base routes for the Authenticator component.
|
|
5
|
+
*
|
|
6
|
+
* @constant {Record<string, string>} BASE_ROUTES
|
|
7
|
+
* @property {string} HOME - The home route.
|
|
8
|
+
* @property {string} NOT_FOUND - The not found route.
|
|
9
|
+
* @property {string} LOGIN - The login route.
|
|
10
|
+
*/
|
|
11
|
+
declare const BASE_ROUTES: Record<string, string>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The props for the Authenticator component.
|
|
15
|
+
*
|
|
16
|
+
* @interface IAuthenticatorProps
|
|
17
|
+
* @property {ReactNode} children - The children of the component.
|
|
18
|
+
* @property {boolean} [isAuthenticated=false] - Whether the user is authenticated.
|
|
19
|
+
* @property {Record<string, string>} [extendRoutes={}] - The extend routes.
|
|
20
|
+
* @property {string} [routeToGoWhenUnauthenticated="/"] - The route to go when the user is not authenticated.
|
|
21
|
+
* @property {string} [routeToGoWhenAuthenticated="/"] - The route to go when the user is authenticated.
|
|
22
|
+
*/
|
|
23
|
+
interface IAuthenticatorProps {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
isAuthenticated?: boolean;
|
|
26
|
+
extendRoutes?: Record<string, string>;
|
|
27
|
+
routeToGoWhenUnauthenticated?: string;
|
|
28
|
+
routeToGoWhenAuthenticated?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The Authenticator component.
|
|
33
|
+
*
|
|
34
|
+
* @param {IAuthenticatorProps} props - The props for the component.
|
|
35
|
+
* @returns {React.ReactNode} The component.
|
|
36
|
+
*/
|
|
37
|
+
declare const Authenticator: ({ children, isAuthenticated, extendRoutes, routeToGoWhenUnauthenticated, routeToGoWhenAuthenticated, }: IAuthenticatorProps) => ReactNode;
|
|
38
|
+
|
|
39
|
+
export { Authenticator, BASE_ROUTES, type IAuthenticatorProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The base routes for the Authenticator component.
|
|
5
|
+
*
|
|
6
|
+
* @constant {Record<string, string>} BASE_ROUTES
|
|
7
|
+
* @property {string} HOME - The home route.
|
|
8
|
+
* @property {string} NOT_FOUND - The not found route.
|
|
9
|
+
* @property {string} LOGIN - The login route.
|
|
10
|
+
*/
|
|
11
|
+
declare const BASE_ROUTES: Record<string, string>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The props for the Authenticator component.
|
|
15
|
+
*
|
|
16
|
+
* @interface IAuthenticatorProps
|
|
17
|
+
* @property {ReactNode} children - The children of the component.
|
|
18
|
+
* @property {boolean} [isAuthenticated=false] - Whether the user is authenticated.
|
|
19
|
+
* @property {Record<string, string>} [extendRoutes={}] - The extend routes.
|
|
20
|
+
* @property {string} [routeToGoWhenUnauthenticated="/"] - The route to go when the user is not authenticated.
|
|
21
|
+
* @property {string} [routeToGoWhenAuthenticated="/"] - The route to go when the user is authenticated.
|
|
22
|
+
*/
|
|
23
|
+
interface IAuthenticatorProps {
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
isAuthenticated?: boolean;
|
|
26
|
+
extendRoutes?: Record<string, string>;
|
|
27
|
+
routeToGoWhenUnauthenticated?: string;
|
|
28
|
+
routeToGoWhenAuthenticated?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The Authenticator component.
|
|
33
|
+
*
|
|
34
|
+
* @param {IAuthenticatorProps} props - The props for the component.
|
|
35
|
+
* @returns {React.ReactNode} The component.
|
|
36
|
+
*/
|
|
37
|
+
declare const Authenticator: ({ children, isAuthenticated, extendRoutes, routeToGoWhenUnauthenticated, routeToGoWhenAuthenticated, }: IAuthenticatorProps) => ReactNode;
|
|
38
|
+
|
|
39
|
+
export { Authenticator, BASE_ROUTES, type IAuthenticatorProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from'react';import {useLocation,Navigate}from'react-router-dom';import N from'@purr-core/hooks.block';var e={HOME:"/",NOT_FOUND:"*",LOGIN:"/login"};var x=({children:f,isAuthenticated:i=false,extendRoutes:s,routeToGoWhenUnauthenticated:m,routeToGoWhenAuthenticated:n})=>{let p=useLocation(),r=N(()=>({...e,...s}));return i&&p.pathname===r.LOGIN?n?o.createElement(Navigate,{to:n}):o.createElement(Navigate,{to:r.HOME}):!i&&p.pathname!==r.LOGIN?m?o.createElement(Navigate,{to:m}):o.createElement(Navigate,{to:r.LOGIN}):f};export{x as Authenticator,e as BASE_ROUTES};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-core/components.authenticator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"react": "*",
|
|
26
26
|
"react-dom": "*",
|
|
27
27
|
"react-router-dom": "*",
|
|
28
|
-
"@purr-core/hooks.block": "0.0.
|
|
28
|
+
"@purr-core/hooks.block": "0.0.11"
|
|
29
29
|
},
|
|
30
30
|
"author": "@DinhThienPhuc",
|
|
31
31
|
"license": "ISC",
|