@ssplib/react-components 0.0.81 → 0.0.83

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.
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
- export declare function Login({ imgURL, name, children, loginURL }: {
2
+ export declare function Login({ imgURL, name, children, loginURL, captchaSiteKey, }: {
3
3
  imgURL?: string;
4
4
  loginURL: string;
5
5
  children: JSX.Element | JSX.Element[];
6
6
  name?: string;
7
+ captchaSiteKey: string;
7
8
  }): JSX.Element;
@@ -36,12 +36,16 @@ const React = __importStar(require("react"));
36
36
  const react_1 = require("react");
37
37
  const auth_1 = require("../../context/auth");
38
38
  const FormProvider_1 = __importDefault(require("../providers/FormProvider"));
39
- function Login({ imgURL = '', name = 'Login', children, loginURL }) {
39
+ const react_google_recaptcha_1 = __importDefault(require("react-google-recaptcha"));
40
+ function Login({ imgURL = '', name = 'Login', children, loginURL, captchaSiteKey, }) {
40
41
  const [loading, setLoading] = (0, react_1.useState)(false);
41
42
  const [error, setError] = (0, react_1.useState)(false);
43
+ const [captchaSolved, setCaptchaSolved] = (0, react_1.useState)(false);
44
+ const [captchaToken, setCaptchaToken] = (0, react_1.useState)('');
45
+ const captcha = (0, react_1.useRef)(null);
42
46
  const { adLogin } = (0, react_1.useContext)(auth_1.AuthContext);
43
47
  function onLogin(data) {
44
- adLogin(loginURL, data, setLoading, setError);
48
+ adLogin(loginURL, data, setLoading, setError, captchaToken);
45
49
  }
46
50
  return (React.createElement(FormProvider_1.default, { onSubmit: onLogin },
47
51
  React.createElement(Container_1.default, { component: 'main', maxWidth: 'xs' },
@@ -55,7 +59,10 @@ function Login({ imgURL = '', name = 'Login', children, loginURL }) {
55
59
  React.createElement(Typography_1.default, { component: 'h1', variant: 'h5', paddingY: 3 }, name),
56
60
  React.createElement(material_1.Stack, { spacing: 3, width: 300 },
57
61
  React.createElement(material_1.Stack, { spacing: 1 }, children),
58
- React.createElement(lab_1.LoadingButton, { type: 'submit', fullWidth: true, variant: 'contained', loading: loading }, "Login"),
62
+ React.createElement(lab_1.LoadingButton, { type: 'submit', fullWidth: true, variant: 'contained', loading: loading, disabled: !captchaSolved }, "Login"),
63
+ React.createElement(react_google_recaptcha_1.default, { ref: captcha, hl: 'pt', sitekey: captchaSiteKey, onExpired: () => setCaptchaSolved(false), onChange: (e) => {
64
+ setCaptchaToken(e), e && setCaptchaSolved(true);
65
+ } }),
59
66
  error && (React.createElement(Box_1.default, { bgcolor: '#ce4257', padding: 2, borderRadius: 2, color: 'white' },
60
67
  React.createElement(Typography_1.default, null, "Dados incorretos. Tente novamente!"))))))));
61
68
  }
@@ -72,11 +72,11 @@ function LoginProvider({ children, AUTH_URL, redirectURL = '/', validateTokenRou
72
72
  }
73
73
  });
74
74
  }, []);
75
- function adLogin(loginURL, data, setLoading, setError) {
75
+ function adLogin(loginURL, data, setLoading, setError, captchaToken) {
76
76
  setLoading(true);
77
77
  fetch(loginURL, {
78
78
  method: 'POST',
79
- body: JSON.stringify(Object.assign(Object.assign({}, data), { cpf: data.cpf.replaceAll(/[.-]/g, '') })),
79
+ body: JSON.stringify(Object.assign(Object.assign({}, data), { cpf: data.cpf.replaceAll(/[.-]/g, ''), captchaToken })),
80
80
  headers: {
81
81
  'Content-Type': 'application/json',
82
82
  },
@@ -13,12 +13,13 @@ interface OiDcConfig {
13
13
  CODE_VERIFIER: string;
14
14
  }
15
15
  export declare const cookieName = "nextauth.token";
16
- export declare function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTokenRoute, testToken, }: {
16
+ export declare function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTokenRoute, testToken, testIP, }: {
17
17
  children: JSX.Element | JSX.Element[];
18
18
  AUTH_URL: string;
19
19
  oidcConfig: OiDcConfig;
20
20
  redirectURL: string;
21
21
  validateTokenRoute: string;
22
22
  testToken: string;
23
+ testIP?: string;
23
24
  }): JSX.Element;
24
25
  export {};
@@ -43,7 +43,7 @@ const react_1 = __importStar(require("react"));
43
43
  const auth_1 = require("../../context/auth");
44
44
  exports.cookieName = 'nextauth.token';
45
45
  const userImgName = 'user-data.img';
46
- function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTokenRoute, testToken, }) {
46
+ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTokenRoute, testToken, testIP, }) {
47
47
  const govBrURL = oidcConfig.authority + '/authorize?response_type=code&client_id=' + oidcConfig.client_id + '&scope=' + oidcConfig.scope + '&redirect_uri=' + oidcConfig.redirect_uri;
48
48
  const [user, setUser] = (0, react_1.useState)();
49
49
  const [userLoaded, setUserLoaded] = (0, react_1.useState)(false);
@@ -75,7 +75,7 @@ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTo
75
75
  }, []);
76
76
  function login() {
77
77
  // Teste em localhost
78
- if (location && location.hostname === 'localhost') {
78
+ if (location && (location.hostname === 'localhost' || location.hostname === testIP)) {
79
79
  const token = testToken;
80
80
  (0, cookies_next_1.setCookie)(exports.cookieName, token);
81
81
  setUser({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.81",
3
+ "version": "0.0.83",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",
package/types/auth.d.ts CHANGED
@@ -67,7 +67,7 @@ export interface AuthReturnData {
67
67
  user: User | null | undefined;
68
68
  userLoaded: boolean;
69
69
  login: () => void;
70
- adLogin: (loginURL: string, data: any, setLoading: React.Dispatch<React.SetStateAction<boolean>>, setError: React.Dispatch<React.SetStateAction<boolean>>) => void;
70
+ adLogin: (loginURL: string, data: any, setLoading: React.Dispatch<React.SetStateAction<boolean>>, setError: React.Dispatch<React.SetStateAction<boolean>>, captchaToken: string) => void;
71
71
  saveUserData: (token: AuthReturn) => void;
72
72
  logout: () => void;
73
73
  }