ag-common 0.0.397 → 0.0.398

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.
@@ -3,7 +3,6 @@ export * from './Button';
3
3
  export * from './Chevron';
4
4
  export * from './Close';
5
5
  export * from './Confirm';
6
- export * from './DashboardAuthValidation';
7
6
  export * from './DropdownList';
8
7
  export * from './FlexColumn';
9
8
  export * from './FlexRow';
@@ -19,7 +19,6 @@ __exportStar(require("./Button"), exports);
19
19
  __exportStar(require("./Chevron"), exports);
20
20
  __exportStar(require("./Close"), exports);
21
21
  __exportStar(require("./Confirm"), exports);
22
- __exportStar(require("./DashboardAuthValidation"), exports);
23
22
  __exportStar(require("./DropdownList"), exports);
24
23
  __exportStar(require("./FlexColumn"), exports);
25
24
  __exportStar(require("./FlexRow"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.397",
3
+ "version": "0.0.398",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -44,9 +44,9 @@
44
44
  "@storybook/react": "6.5.15",
45
45
  "@storybook/theming": "6.5.15",
46
46
  "@types/jsonwebtoken": "9.0.0",
47
- "@types/node": "18.11.17",
47
+ "@types/node": "18.11.18",
48
48
  "@types/react": "18.0.26",
49
- "@types/react-dom": "18.0.9",
49
+ "@types/react-dom": "18.0.10",
50
50
  "@emotion/react": "11.10.5",
51
51
  "@emotion/styled": "11.10.5",
52
52
  "cross-env": "7.0.3",
@@ -1,27 +0,0 @@
1
- /// <reference types="react" />
2
- import { AuthedUserContext } from '../../helpers/jwt';
3
- import { IRequestCommon } from '../../helpers/routes';
4
- /**
5
- *
6
- * @param param0 handles auth loading/error
7
- * @returns
8
- */
9
- export declare const DashboardAuthValidation: ({ rc: { request, pushPath }, cac: { error: authError, loginWithRedirect, logout, isAuthenticated, loading: authLoading, }, getDashboardPath, getUnauthedPage, addToast, }: {
10
- addToast: (m: string, options?: {
11
- appearance: 'error' | 'success';
12
- autoClose?: number;
13
- } | undefined) => void;
14
- getDashboardPath: () => string;
15
- /**
16
- * will goto when landing on page without auth. undefined will not redirect
17
- */
18
- getUnauthedPage: undefined | (() => string);
19
- cac: AuthedUserContext;
20
- rc: {
21
- request: IRequestCommon;
22
- pushPath: (p: string) => Promise<void>;
23
- };
24
- }) => {
25
- render?: JSX.Element | undefined;
26
- openApiDisabled: boolean;
27
- };
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DashboardAuthValidation = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const log_1 = require("../../../common/helpers/log");
9
- const base64_1 = require("../../../common/helpers/string/base64");
10
- const useGranularHook_1 = require("../../helpers/useGranularHook");
11
- const useQueryString_1 = require("../../helpers/useQueryString");
12
- const Loader_1 = require("../Loader");
13
- /**
14
- *
15
- * @param param0 handles auth loading/error
16
- * @returns
17
- */
18
- const DashboardAuthValidation = ({ rc: { request, pushPath }, cac: { error: authError, loginWithRedirect, logout, isAuthenticated, loading: authLoading, }, getDashboardPath, getUnauthedPage, addToast, }) => {
19
- (0, useGranularHook_1.useGranularEffect)(() => {
20
- if (authError) {
21
- const emailOption = authError.message.includes('email')
22
- ? ` We require the use of your email for the functionality of this app.
23
- You can update your settings at https://www.facebook.com/settings?tab=applications`
24
- : '';
25
- addToast(`An Error has occured with your login attempt.${emailOption}`, {
26
- appearance: 'error',
27
- });
28
- (0, log_1.error)(`auth error:`, JSON.stringify(authError, null, 2));
29
- void logout();
30
- }
31
- }, [authError], [authError, addToast, logout]);
32
- const forceLogin = Object.keys(request.url.query || {}).includes('login');
33
- if (forceLogin) {
34
- if (!isAuthenticated) {
35
- void loginWithRedirect(request.url.query.state);
36
- return { render: react_1.default.createElement(react_1.default.Fragment, null), openApiDisabled: true };
37
- }
38
- if (isAuthenticated) {
39
- void pushPath(getDashboardPath());
40
- return { render: react_1.default.createElement(react_1.default.Fragment, null), openApiDisabled: true };
41
- }
42
- }
43
- if (request.url.query.state && isAuthenticated) {
44
- const decoded = JSON.parse((0, base64_1.fromBase64)(request.url.query.state));
45
- if (decoded.redirect) {
46
- void pushPath(decoded.redirect);
47
- return { render: react_1.default.createElement(react_1.default.Fragment, null), openApiDisabled: true };
48
- }
49
- }
50
- const serverAuthLoading = useQueryString_1.isServer &&
51
- !authError &&
52
- !authLoading &&
53
- !isAuthenticated &&
54
- Object.keys(request.url.query || {}).includes('code');
55
- if (authLoading || serverAuthLoading) {
56
- return {
57
- render: react_1.default.createElement(Loader_1.Loader, { name: "authload" }),
58
- openApiDisabled: true,
59
- };
60
- }
61
- if (!isAuthenticated && !authLoading && !authError && getUnauthedPage) {
62
- void pushPath(getUnauthedPage());
63
- return { render: react_1.default.createElement(react_1.default.Fragment, null), openApiDisabled: true };
64
- }
65
- const openApiDisabled = !isAuthenticated || authLoading || !!authError;
66
- return { openApiDisabled };
67
- };
68
- exports.DashboardAuthValidation = DashboardAuthValidation;