@purr-core/components.authenticator 0.0.1

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.
@@ -0,0 +1 @@
1
+ export declare const BASE_ROUTES: Record<string, string>;
@@ -0,0 +1,3 @@
1
+ import { IAuthenticatorProps } from './_types';
2
+
3
+ export declare const Authenticator: ({ children, isAuthenticated, extendRoutes, routeToGoWhenUnauthenticated, routeToGoWhenAuthenticated, }: IAuthenticatorProps) => JSX.Element;
@@ -0,0 +1,7 @@
1
+ export interface IAuthenticatorProps {
2
+ children: JSX.Element;
3
+ isAuthenticated?: boolean;
4
+ extendRoutes?: Record<string, string>;
5
+ routeToGoWhenUnauthenticated?: string;
6
+ routeToGoWhenAuthenticated?: string;
7
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),t=require("react-router-dom"),O=require("@purr-core/hooks.block"),n={HOME:"/",NOT_FOUND:"*",LOGIN:"/login"},N=({children:u,isAuthenticated:o=!1,extendRoutes:c,routeToGoWhenUnauthenticated:s,routeToGoWhenAuthenticated:a})=>{const i=t.useLocation(),e=O(()=>({...n,...c}));return o&&i.pathname===e.LOGIN?a?r.jsx(t.Navigate,{to:a}):r.jsx(t.Navigate,{to:e.HOME}):!o&&i.pathname!==e.LOGIN?s?r.jsx(t.Navigate,{to:s}):r.jsx(t.Navigate,{to:e.LOGIN}):u};exports.Authenticator=N;exports.BASE_ROUTES=n;
@@ -0,0 +1,3 @@
1
+ export * from './_base-routes';
2
+ export * from './_components';
3
+ export * from './_types';
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { useLocation as N, Navigate as t } from "react-router-dom";
3
+ import a from "@purr-core/hooks.block";
4
+ const p = {
5
+ HOME: "/",
6
+ NOT_FOUND: "*",
7
+ LOGIN: "/login"
8
+ }, l = ({
9
+ children: m,
10
+ isAuthenticated: n = !1,
11
+ extendRoutes: s,
12
+ routeToGoWhenUnauthenticated: O,
13
+ routeToGoWhenAuthenticated: f
14
+ }) => {
15
+ const i = N(), o = a(() => ({
16
+ ...p,
17
+ ...s
18
+ }));
19
+ return n && i.pathname === o.LOGIN ? f ? /* @__PURE__ */ r(t, { to: f }) : /* @__PURE__ */ r(t, { to: o.HOME }) : !n && i.pathname !== o.LOGIN ? O ? /* @__PURE__ */ r(t, { to: O }) : /* @__PURE__ */ r(t, { to: o.LOGIN }) : m;
20
+ };
21
+ export {
22
+ l as Authenticator,
23
+ p as BASE_ROUTES
24
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@purr-core/components.authenticator",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "typescript": "*",
25
+ "react": "*",
26
+ "react-router-dom": "*",
27
+ "@purr-core/hooks.block": "0.0.3"
28
+ },
29
+ "author": "@DinhThienPhuc",
30
+ "license": "ISC",
31
+ "description": "",
32
+ "sideEffects": false,
33
+ "scripts": {
34
+ "dev": "vite build --watch",
35
+ "build": "tsc && vite build",
36
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
37
+ }
38
+ }