@ttoss/react-auth-core 0.4.29 → 0.4.30

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.js DELETED
@@ -1,1130 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import * as React from 'react';
3
- "use strict";
4
-
5
- var __create = Object.create;
6
- var __defProp = Object.defineProperty;
7
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
- var __getOwnPropNames = Object.getOwnPropertyNames;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __name = (target, value) => __defProp(target, "name", {
12
- value,
13
- configurable: true
14
- });
15
- var __export = (target, all) => {
16
- for (var name in all) __defProp(target, name, {
17
- get: all[name],
18
- enumerable: true
19
- });
20
- };
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") {
23
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
24
- get: () => from[key],
25
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
26
- });
27
- }
28
- return to;
29
- };
30
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
36
- value: mod,
37
- enumerable: true
38
- }) : target, mod));
39
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
40
- value: true
41
- }), mod);
42
-
43
- // src/index.ts
44
- var index_exports = {};
45
- __export(index_exports, {
46
- Auth: () => Auth,
47
- AuthConfirmSignUpCheckEmail: () => AuthConfirmSignUpCheckEmail,
48
- AuthConfirmSignUpWithCode: () => AuthConfirmSignUpWithCode,
49
- AuthForgotPassword: () => AuthForgotPassword,
50
- AuthForgotPasswordResetPassword: () => AuthForgotPasswordResetPassword,
51
- AuthFullScreen: () => AuthFullScreen,
52
- AuthProvider: () => AuthProvider,
53
- AuthSignIn: () => AuthSignIn,
54
- AuthSignUp: () => AuthSignUp,
55
- ErrorBoundary: () => ErrorBoundary,
56
- useAuth: () => useAuth,
57
- useAuthScreen: () => useAuthScreen
58
- });
59
- module.exports = __toCommonJS(index_exports);
60
-
61
- // src/Auth.tsx
62
- var import_react_notifications6 = require("@ttoss/react-notifications");
63
- var import_ui7 = require("@ttoss/ui");
64
- var React5 = __toESM(require("react"), 1);
65
-
66
- // src/AuthCard.tsx
67
- var import_react_notifications = require("@ttoss/react-notifications");
68
- var import_ui = require("@ttoss/ui");
69
- var React2 = __toESM(require("react"), 1);
70
- var LogoContext = /* @__PURE__ */React2.createContext({});
71
- var LogoProvider = /* @__PURE__ */__name(({
72
- children,
73
- ...values
74
- }) => {
75
- return /* @__PURE__ */React2.createElement(LogoContext.Provider, {
76
- value: values
77
- }, children);
78
- }, "LogoProvider");
79
- var AuthCard = /* @__PURE__ */__name(({
80
- children,
81
- title,
82
- buttonLabel,
83
- extraButton,
84
- isValidForm
85
- }) => {
86
- const {
87
- logo
88
- } = React2.useContext(LogoContext);
89
- const {
90
- isLoading
91
- } = (0, import_react_notifications.useNotifications)();
92
- return /* @__PURE__ */React2.createElement(import_ui.Box, {
93
- sx: {
94
- maxWidth: "400px",
95
- width: "full",
96
- border: "md",
97
- borderColor: "display.border.muted.default",
98
- paddingX: "8",
99
- paddingY: "9",
100
- backgroundColor: "surface"
101
- }
102
- }, logo && /* @__PURE__ */React2.createElement(import_ui.Flex, {
103
- sx: {
104
- width: "full",
105
- maxHeight: "90px",
106
- justifyContent: "center",
107
- marginBottom: "8"
108
- }
109
- }, logo), /* @__PURE__ */React2.createElement(import_ui.Flex, {
110
- sx: {
111
- flexDirection: "column"
112
- }
113
- }, /* @__PURE__ */React2.createElement(import_ui.Heading, {
114
- as: "h2",
115
- variant: "h2",
116
- sx: {
117
- marginBottom: "8"
118
- }
119
- }, title), children, /* @__PURE__ */React2.createElement(import_ui.Flex, {
120
- sx: {
121
- flexDirection: "column",
122
- width: "100%",
123
- gap: "7",
124
- marginTop: "8"
125
- }
126
- }, /* @__PURE__ */React2.createElement(import_ui.Button, {
127
- type: "submit",
128
- variant: "accent",
129
- disabled: isLoading || !isValidForm,
130
- sx: {
131
- textAlign: "center",
132
- display: "initial"
133
- },
134
- loading: isLoading
135
- }, buttonLabel), extraButton)));
136
- }, "AuthCard");
137
-
138
- // src/AuthConfirmSignUpCheckEmail.tsx
139
- var import_NotificationCard = require("@ttoss/components/NotificationCard");
140
- var import_react_i18n = require("@ttoss/react-i18n");
141
- var AuthConfirmSignUpCheckEmail = /* @__PURE__ */__name(({
142
- onConfirmSignUpCheckEmail
143
- }) => {
144
- const {
145
- intl
146
- } = (0, import_react_i18n.useI18n)();
147
- return /* @__PURE__ */React.createElement("form", {
148
- onSubmit: /* @__PURE__ */__name(e => {
149
- e.preventDefault();
150
- onConfirmSignUpCheckEmail();
151
- }, "onSubmit")
152
- }, /* @__PURE__ */React.createElement(AuthCard, {
153
- isValidForm: true,
154
- buttonLabel: intl.formatMessage({
155
- id: "38HSjr",
156
- defaultMessage: [{
157
- "type": 0,
158
- "value": "Sign In"
159
- }]
160
- }),
161
- title: intl.formatMessage({
162
- id: "cGR2eI",
163
- defaultMessage: [{
164
- "type": 0,
165
- "value": "Confirmation"
166
- }]
167
- })
168
- }, /* @__PURE__ */React.createElement(import_NotificationCard.NotificationCard, {
169
- type: "info",
170
- message: intl.formatMessage({
171
- id: "qTQ4hP",
172
- defaultMessage: [{
173
- "type": 0,
174
- "value": "An email has been sent to your address. Please check your inbox and follow the instructions to confirm your sign up."
175
- }]
176
- })
177
- })));
178
- }, "AuthConfirmSignUpCheckEmail");
179
-
180
- // src/AuthConfirmSignUpWithCode.tsx
181
- var import_NotificationCard2 = require("@ttoss/components/NotificationCard");
182
- var import_forms = require("@ttoss/forms");
183
- var import_react_i18n2 = require("@ttoss/react-i18n");
184
- var AuthConfirmSignUpWithCode = /* @__PURE__ */__name(({
185
- email,
186
- onConfirmSignUpWithCode
187
- }) => {
188
- const {
189
- intl
190
- } = (0, import_react_i18n2.useI18n)();
191
- const schema = import_forms.yup.object().shape({
192
- code: import_forms.yup.string().required(intl.formatMessage({
193
- id: "0XOzcH",
194
- defaultMessage: [{
195
- "type": 0,
196
- "value": "Required field"
197
- }]
198
- })).max(6, intl.formatMessage({
199
- id: "S3pjKw",
200
- defaultMessage: [{
201
- "type": 0,
202
- "value": "Minimum "
203
- }, {
204
- "type": 1,
205
- "value": "value"
206
- }, {
207
- "type": 0,
208
- "value": " characters"
209
- }]
210
- }, {
211
- value: 6
212
- }))
213
- }).required();
214
- const formMethods = (0, import_forms.useForm)({
215
- resolver: (0, import_forms.yupResolver)(schema)
216
- });
217
- return /* @__PURE__ */React.createElement(import_forms.Form, {
218
- ...formMethods,
219
- onSubmit: /* @__PURE__ */__name(({
220
- code
221
- }) => {
222
- return onConfirmSignUpWithCode({
223
- code,
224
- email
225
- });
226
- }, "onSubmit")
227
- }, /* @__PURE__ */React.createElement(AuthCard, {
228
- buttonLabel: intl.formatMessage({
229
- id: "UNttd+",
230
- defaultMessage: [{
231
- "type": 0,
232
- "value": "Confirm"
233
- }]
234
- }),
235
- isValidForm: formMethods.formState.isValid,
236
- title: intl.formatMessage({
237
- id: "cGR2eI",
238
- defaultMessage: [{
239
- "type": 0,
240
- "value": "Confirmation"
241
- }]
242
- })
243
- }, /* @__PURE__ */React.createElement(import_NotificationCard2.NotificationCard, {
244
- type: "info",
245
- message: intl.formatMessage({
246
- id: "pwv2cR",
247
- defaultMessage: [{
248
- "type": 0,
249
- "value": "We have sent a confirmation code to your email address. Please enter the code below."
250
- }]
251
- })
252
- }), /* @__PURE__ */React.createElement(import_forms.FormFieldInput, {
253
- sx: {
254
- marginTop: "6"
255
- },
256
- name: "code",
257
- label: intl.formatMessage({
258
- id: "KY2T6J",
259
- defaultMessage: [{
260
- "type": 0,
261
- "value": "Code"
262
- }]
263
- })
264
- })));
265
- }, "AuthConfirmSignUpWithCode");
266
-
267
- // src/AuthForgotPassword.tsx
268
- var import_forms2 = require("@ttoss/forms");
269
- var import_react_i18n3 = require("@ttoss/react-i18n");
270
- var import_react_notifications2 = require("@ttoss/react-notifications");
271
- var import_ui2 = require("@ttoss/ui");
272
- var AuthForgotPassword = /* @__PURE__ */__name(props => {
273
- const {
274
- intl
275
- } = (0, import_react_i18n3.useI18n)();
276
- const schema = import_forms2.yup.object().shape({
277
- email: import_forms2.yup.string().email(intl.formatMessage({
278
- id: "9cApwd",
279
- defaultMessage: [{
280
- "type": 0,
281
- "value": "Please, insert a valid e-mail"
282
- }]
283
- })).required()
284
- }).required();
285
- const formMethods = (0, import_forms2.useForm)({
286
- resolver: (0, import_forms2.yupResolver)(schema),
287
- mode: "onChange"
288
- });
289
- return /* @__PURE__ */React.createElement(import_forms2.Form, {
290
- ...formMethods,
291
- sx: {
292
- maxWidth: "390px"
293
- },
294
- onSubmit: /* @__PURE__ */__name(({
295
- email
296
- }) => {
297
- return props.onForgotPassword({
298
- email
299
- });
300
- }, "onSubmit")
301
- }, /* @__PURE__ */React.createElement(AuthCard, {
302
- buttonLabel: intl.formatMessage({
303
- id: "mZzmNV",
304
- defaultMessage: [{
305
- "type": 0,
306
- "value": "Recover Password"
307
- }]
308
- }),
309
- isValidForm: formMethods.formState.isValid,
310
- title: intl.formatMessage({
311
- id: "S4bbEj",
312
- defaultMessage: [{
313
- "type": 0,
314
- "value": "Recovering Password"
315
- }]
316
- }),
317
- extraButton: /* @__PURE__ */React.createElement(import_ui2.Button, {
318
- sx: {
319
- textAlign: "center",
320
- display: "initial"
321
- },
322
- variant: "secondary",
323
- onClick: props.onGoToSignIn
324
- }, intl.formatMessage({
325
- id: "6PdOcy",
326
- defaultMessage: [{
327
- "type": 0,
328
- "value": "Cancel"
329
- }]
330
- }))
331
- }, /* @__PURE__ */React.createElement(import_forms2.FormFieldInput, {
332
- name: "email",
333
- label: intl.formatMessage({
334
- id: "XreZg+",
335
- defaultMessage: [{
336
- "type": 0,
337
- "value": "Registered Email"
338
- }]
339
- })
340
- }), /* @__PURE__ */React.createElement(import_react_notifications2.NotificationsBox, null), props.onGoToSignUp && /* @__PURE__ */React.createElement(import_ui2.Text, {
341
- sx: {
342
- marginTop: "xl",
343
- cursor: "pointer"
344
- },
345
- as: import_ui2.Link,
346
- onClick: props.onGoToSignUp
347
- }, intl.formatMessage({
348
- id: "lZvoYL",
349
- defaultMessage: [{
350
- "type": 0,
351
- "value": "Sign up now"
352
- }]
353
- }))));
354
- }, "AuthForgotPassword");
355
-
356
- // src/AuthForgotPasswordResetPassword.tsx
357
- var import_forms3 = require("@ttoss/forms");
358
- var import_react_i18n4 = require("@ttoss/react-i18n");
359
- var import_react_notifications3 = require("@ttoss/react-notifications");
360
- var import_ui3 = require("@ttoss/ui");
361
- var AuthForgotPasswordResetPassword = /* @__PURE__ */__name(props => {
362
- const {
363
- intl
364
- } = (0, import_react_i18n4.useI18n)();
365
- const codeValidation = import_forms3.yup.string().required(intl.formatMessage({
366
- id: "0XOzcH",
367
- defaultMessage: [{
368
- "type": 0,
369
- "value": "Required field"
370
- }]
371
- }));
372
- const schema = import_forms3.yup.object().shape({
373
- code: props.maxCodeLength ? codeValidation.min(props.maxCodeLength, intl.formatMessage({
374
- id: "S3pjKw",
375
- defaultMessage: [{
376
- "type": 0,
377
- "value": "Minimum "
378
- }, {
379
- "type": 1,
380
- "value": "value"
381
- }, {
382
- "type": 0,
383
- "value": " characters"
384
- }]
385
- }, {
386
- value: props.maxCodeLength
387
- })).max(props.maxCodeLength, intl.formatMessage({
388
- id: "SfWKyS",
389
- defaultMessage: [{
390
- "type": 0,
391
- "value": "Maximum "
392
- }, {
393
- "type": 1,
394
- "value": "value"
395
- }, {
396
- "type": 0,
397
- "value": " characters"
398
- }]
399
- }, {
400
- value: props.maxCodeLength
401
- })) : codeValidation,
402
- newPassword: import_forms3.yup.string().required(intl.formatMessage({
403
- id: "kdFYba",
404
- defaultMessage: [{
405
- "type": 0,
406
- "value": "Password field is required"
407
- }]
408
- })).min(props.passwordMinimumLength || 8, intl.formatMessage({
409
- id: "TZ4WUk",
410
- defaultMessage: [{
411
- "type": 0,
412
- "value": "Password requires "
413
- }, {
414
- "type": 1,
415
- "value": "value"
416
- }, {
417
- "type": 0,
418
- "value": " characters"
419
- }]
420
- }, {
421
- value: props.passwordMinimumLength || 8
422
- })).trim()
423
- });
424
- const formMethods = (0, import_forms3.useForm)({
425
- resolver: (0, import_forms3.yupResolver)(schema),
426
- mode: "onChange"
427
- });
428
- return /* @__PURE__ */React.createElement(import_forms3.Form, {
429
- ...formMethods,
430
- sx: {
431
- maxWidth: "390px"
432
- },
433
- onSubmit: /* @__PURE__ */__name(({
434
- code,
435
- newPassword
436
- }) => {
437
- return props.onForgotPasswordResetPassword({
438
- email: props.email,
439
- code,
440
- newPassword
441
- });
442
- }, "onSubmit")
443
- }, /* @__PURE__ */React.createElement(AuthCard, {
444
- buttonLabel: intl.formatMessage({
445
- id: "HT4tSM",
446
- defaultMessage: [{
447
- "type": 0,
448
- "value": "Reset Password"
449
- }]
450
- }),
451
- isValidForm: formMethods.formState.isValid,
452
- title: intl.formatMessage({
453
- id: "HT4tSM",
454
- defaultMessage: [{
455
- "type": 0,
456
- "value": "Reset Password"
457
- }]
458
- }),
459
- extraButton: props.onGoToSignIn ? /* @__PURE__ */React.createElement(import_ui3.Button, {
460
- type: "button",
461
- sx: {
462
- textAlign: "center",
463
- display: "initial"
464
- },
465
- variant: "secondary",
466
- onClick: props.onGoToSignIn
467
- }, intl.formatMessage({
468
- id: "6PdOcy",
469
- defaultMessage: [{
470
- "type": 0,
471
- "value": "Cancel"
472
- }]
473
- })) : null
474
- }, /* @__PURE__ */React.createElement(import_forms3.FormFieldInput, {
475
- name: "code",
476
- label: intl.formatMessage({
477
- id: "s1OmP0",
478
- defaultMessage: [{
479
- "type": 0,
480
- "value": "Confirmation code"
481
- }]
482
- })
483
- }), /* @__PURE__ */React.createElement(import_forms3.FormFieldPassword, {
484
- name: "newPassword",
485
- label: intl.formatMessage({
486
- id: "e3IQoc",
487
- defaultMessage: [{
488
- "type": 0,
489
- "value": "New Password"
490
- }]
491
- })
492
- }), /* @__PURE__ */React.createElement(import_react_notifications3.NotificationsBox, null)));
493
- }, "AuthForgotPasswordResetPassword");
494
-
495
- // src/AuthFullScreen.tsx
496
- var import_ui4 = require("@ttoss/ui");
497
- var AuthFullScreen = /* @__PURE__ */__name(({
498
- children
499
- }) => {
500
- return /* @__PURE__ */React.createElement(import_ui4.Flex, {
501
- sx: {
502
- height: "100vh",
503
- width: "100vw",
504
- justifyContent: "center",
505
- alignItems: "center",
506
- margin: 0,
507
- backgroundPosition: "center",
508
- backgroundRepeat: "no-repeat",
509
- backgroundSize: "cover"
510
- }
511
- }, children);
512
- }, "AuthFullScreen");
513
-
514
- // src/AuthSignIn.tsx
515
- var import_forms4 = require("@ttoss/forms");
516
- var import_react_i18n5 = require("@ttoss/react-i18n");
517
- var import_react_notifications4 = require("@ttoss/react-notifications");
518
- var import_ui5 = require("@ttoss/ui");
519
- var AuthSignIn = /* @__PURE__ */__name(({
520
- onSignIn,
521
- onGoToSignUp,
522
- defaultValues,
523
- onGoToForgotPassword,
524
- passwordMinimumLength = 8
525
- }) => {
526
- const {
527
- intl
528
- } = (0, import_react_i18n5.useI18n)();
529
- const schema = import_forms4.yup.object().shape({
530
- email: import_forms4.yup.string().required(intl.formatMessage({
531
- id: "d1YCuH",
532
- defaultMessage: [{
533
- "type": 0,
534
- "value": "Enter your email address"
535
- }]
536
- })).email(intl.formatMessage({
537
- id: "9cApwd",
538
- defaultMessage: [{
539
- "type": 0,
540
- "value": "Please, insert a valid e-mail"
541
- }]
542
- })),
543
- password: import_forms4.yup.string().required(intl.formatMessage({
544
- id: "kdFYba",
545
- defaultMessage: [{
546
- "type": 0,
547
- "value": "Password field is required"
548
- }]
549
- })).min(passwordMinimumLength, intl.formatMessage({
550
- id: "TZ4WUk",
551
- defaultMessage: [{
552
- "type": 0,
553
- "value": "Password requires "
554
- }, {
555
- "type": 1,
556
- "value": "value"
557
- }, {
558
- "type": 0,
559
- "value": " characters"
560
- }]
561
- }, {
562
- value: passwordMinimumLength
563
- })).trim()
564
- });
565
- const formMethods = (0, import_forms4.useForm)({
566
- defaultValues,
567
- mode: "onChange",
568
- resolver: (0, import_forms4.yupResolver)(schema)
569
- });
570
- const onSubmitForm = /* @__PURE__ */__name(data => {
571
- return onSignIn(data);
572
- }, "onSubmitForm");
573
- return /* @__PURE__ */React.createElement(import_forms4.Form, {
574
- sx: {
575
- maxWidth: "390px",
576
- width: "100%"
577
- },
578
- ...formMethods,
579
- onSubmit: onSubmitForm
580
- }, /* @__PURE__ */React.createElement(AuthCard, {
581
- title: intl.formatMessage({
582
- id: "SQJto2",
583
- defaultMessage: [{
584
- "type": 0,
585
- "value": "Sign in"
586
- }]
587
- }),
588
- buttonLabel: intl.formatMessage({
589
- id: "SQJto2",
590
- defaultMessage: [{
591
- "type": 0,
592
- "value": "Sign in"
593
- }]
594
- }),
595
- isValidForm: formMethods.formState.isValid,
596
- extraButton: onGoToSignUp ? /* @__PURE__ */React.createElement(import_ui5.Button, {
597
- type: "button",
598
- variant: "secondary",
599
- sx: {
600
- textAlign: "center",
601
- display: "initial"
602
- },
603
- onClick: onGoToSignUp
604
- }, intl.formatMessage({
605
- id: "EZ3YF2",
606
- defaultMessage: [{
607
- "type": 0,
608
- "value": "Sign up"
609
- }]
610
- })) : null
611
- }, /* @__PURE__ */React.createElement(import_ui5.Flex, {
612
- sx: {
613
- flexDirection: "column",
614
- gap: "xl"
615
- }
616
- }, /* @__PURE__ */React.createElement(import_forms4.FormFieldInput, {
617
- name: "email",
618
- label: intl.formatMessage({
619
- id: "5E12mO",
620
- defaultMessage: [{
621
- "type": 0,
622
- "value": "Email"
623
- }]
624
- })
625
- }), /* @__PURE__ */React.createElement(import_forms4.FormFieldPassword, {
626
- name: "password",
627
- label: intl.formatMessage({
628
- id: "PylVqx",
629
- defaultMessage: [{
630
- "type": 0,
631
- "value": "Password"
632
- }]
633
- })
634
- })), onGoToForgotPassword && /* @__PURE__ */React.createElement(import_ui5.Flex, {
635
- sx: {
636
- justifyContent: "space-between",
637
- marginTop: "lg"
638
- }
639
- }, /* @__PURE__ */React.createElement(import_ui5.Text, {
640
- sx: {
641
- marginLeft: "auto",
642
- cursor: "pointer"
643
- },
644
- as: import_ui5.Link,
645
- onClick: onGoToForgotPassword
646
- }, intl.formatMessage({
647
- id: "BtK6KR",
648
- defaultMessage: [{
649
- "type": 0,
650
- "value": "Forgot password?"
651
- }]
652
- }))), /* @__PURE__ */React.createElement(import_react_notifications4.NotificationsBox, null)));
653
- }, "AuthSignIn");
654
-
655
- // src/AuthSignUp.tsx
656
- var import_forms5 = require("@ttoss/forms");
657
- var import_react_i18n6 = require("@ttoss/react-i18n");
658
- var import_react_notifications5 = require("@ttoss/react-notifications");
659
- var import_ui6 = require("@ttoss/ui");
660
- var React3 = __toESM(require("react"), 1);
661
- var AuthSignUp = /* @__PURE__ */__name(props => {
662
- const {
663
- intl
664
- } = (0, import_react_i18n6.useI18n)();
665
- const {
666
- passwordMinimumLength = 8
667
- } = props;
668
- const schema = React3.useMemo(() => {
669
- return import_forms5.yup.object().shape({
670
- email: import_forms5.yup.string().required(intl.formatMessage({
671
- id: "d1YCuH",
672
- defaultMessage: [{
673
- "type": 0,
674
- "value": "Enter your email address"
675
- }]
676
- })).email(intl.formatMessage({
677
- id: "OhDL0i",
678
- defaultMessage: [{
679
- "type": 0,
680
- "value": "Invalid email"
681
- }]
682
- })),
683
- password: import_forms5.yup.string().required(intl.formatMessage({
684
- id: "kdFYba",
685
- defaultMessage: [{
686
- "type": 0,
687
- "value": "Password field is required"
688
- }]
689
- })).min(passwordMinimumLength, intl.formatMessage({
690
- id: "TZ4WUk",
691
- defaultMessage: [{
692
- "type": 0,
693
- "value": "Password requires "
694
- }, {
695
- "type": 1,
696
- "value": "value"
697
- }, {
698
- "type": 0,
699
- "value": " characters"
700
- }]
701
- }, {
702
- value: passwordMinimumLength
703
- })).trim(),
704
- confirmPassword: import_forms5.yup.string().required(intl.formatMessage({
705
- id: "NJ57Qj",
706
- defaultMessage: [{
707
- "type": 0,
708
- "value": "Confirm password field is required"
709
- }]
710
- })).oneOf([import_forms5.yup.ref("password")], intl.formatMessage({
711
- id: "WU/CqP",
712
- defaultMessage: [{
713
- "type": 0,
714
- "value": "Passwords are not the same"
715
- }]
716
- })),
717
- signUpTerms: props.signUpTerms?.isRequired ? import_forms5.yup.boolean().required(intl.formatMessage({
718
- id: "qnQYqN",
719
- defaultMessage: [{
720
- "type": 0,
721
- "value": "You must accept the terms and conditions"
722
- }]
723
- })) : import_forms5.yup.boolean()
724
- });
725
- }, [intl, props.signUpTerms?.isRequired, passwordMinimumLength]);
726
- const signUpTermsLabel = React3.useMemo(() => {
727
- if (!props.signUpTerms) {
728
- return null;
729
- }
730
- const signUpTermsFirstMessage = intl.formatMessage({
731
- id: "Co3exe",
732
- defaultMessage: [{
733
- "type": 0,
734
- "value": "By signing up, you agree to the following Terms and Conditions."
735
- }]
736
- });
737
- const termsLinks = props.signUpTerms.terms.map((term, index, terms) => {
738
- const finalPunctuation = index === terms.length - 1 ? "." : ", ";
739
- return /* @__PURE__ */React3.createElement(React3.Fragment, {
740
- key: index
741
- }, /* @__PURE__ */React3.createElement(import_ui6.Link, {
742
- key: index,
743
- href: term.url,
744
- target: "_blank",
745
- rel: "noreferrer"
746
- }, term.label), finalPunctuation);
747
- });
748
- const label = /* @__PURE__ */React3.createElement(import_ui6.Text, null, signUpTermsFirstMessage, " ", termsLinks);
749
- return label;
750
- }, [intl, props.signUpTerms]);
751
- const signUpTermsNode = React3.useMemo(() => {
752
- if (!props.signUpTerms) {
753
- return null;
754
- }
755
- if (props.signUpTerms.isRequired) {
756
- return /* @__PURE__ */React3.createElement(import_forms5.FormFieldCheckbox, {
757
- name: "signUpTerms",
758
- label: signUpTermsLabel
759
- });
760
- } else {
761
- return /* @__PURE__ */React3.createElement(React3.Fragment, null, signUpTermsLabel);
762
- }
763
- }, [props.signUpTerms, signUpTermsLabel]);
764
- const formMethods = (0, import_forms5.useForm)({
765
- mode: "onChange",
766
- resolver: (0, import_forms5.yupResolver)(schema)
767
- });
768
- const onSubmitForm = /* @__PURE__ */__name(data => {
769
- return props.onSignUp(data);
770
- }, "onSubmitForm");
771
- return /* @__PURE__ */React3.createElement(import_forms5.Form, {
772
- sx: {
773
- maxWidth: "390px",
774
- width: "100%"
775
- },
776
- ...formMethods,
777
- onSubmit: onSubmitForm
778
- }, /* @__PURE__ */React3.createElement(AuthCard, {
779
- buttonLabel: intl.formatMessage({
780
- id: "URJDrG",
781
- defaultMessage: [{
782
- "type": 0,
783
- "value": "Sign up"
784
- }]
785
- }),
786
- title: intl.formatMessage({
787
- id: "oayEC3",
788
- defaultMessage: [{
789
- "type": 0,
790
- "value": "Sign up"
791
- }]
792
- }),
793
- isValidForm: formMethods.formState.isValid,
794
- extraButton: /* @__PURE__ */React3.createElement(import_ui6.Text, {
795
- sx: {
796
- cursor: "pointer"
797
- },
798
- onClick: props.onGoToSignIn,
799
- as: import_ui6.Link
800
- }, intl.formatMessage({
801
- id: "8GMUPk",
802
- defaultMessage: [{
803
- "type": 0,
804
- "value": "I'm already registered"
805
- }]
806
- }))
807
- }, /* @__PURE__ */React3.createElement(import_ui6.Flex, {
808
- sx: {
809
- flexDirection: "column",
810
- gap: "xl"
811
- }
812
- }, /* @__PURE__ */React3.createElement(import_forms5.FormFieldInput, {
813
- name: "email",
814
- label: intl.formatMessage({
815
- id: "5E12mO",
816
- defaultMessage: [{
817
- "type": 0,
818
- "value": "Email"
819
- }]
820
- })
821
- }), /* @__PURE__ */React3.createElement(import_forms5.FormFieldPassword, {
822
- name: "password",
823
- label: intl.formatMessage({
824
- id: "PylVqx",
825
- defaultMessage: [{
826
- "type": 0,
827
- "value": "Password"
828
- }]
829
- })
830
- }), /* @__PURE__ */React3.createElement(import_forms5.FormFieldPassword, {
831
- name: "confirmPassword",
832
- label: intl.formatMessage({
833
- id: "lY+cuM",
834
- defaultMessage: [{
835
- "type": 0,
836
- "value": "Confirm password"
837
- }]
838
- })
839
- }), signUpTermsNode), /* @__PURE__ */React3.createElement(import_react_notifications5.NotificationsBox, null)));
840
- }, "AuthSignUp");
841
-
842
- // src/ErrorBoundary.tsx
843
- var import_NotificationCard3 = require("@ttoss/components/NotificationCard");
844
- var import_logger = require("@ttoss/logger");
845
- var import_react_i18n7 = require("@ttoss/react-i18n");
846
- var import_react_error_boundary = require("react-error-boundary");
847
- var ErrorFallback = /* @__PURE__ */__name(({
848
- resetErrorBoundary
849
- }) => {
850
- const {
851
- intl
852
- } = (0, import_react_i18n7.useI18n)();
853
- return /* @__PURE__ */React.createElement("div", {
854
- role: "alert"
855
- }, /* @__PURE__ */React.createElement(import_NotificationCard3.NotificationCard, {
856
- type: "error",
857
- message: intl.formatMessage({
858
- id: "khMx/2",
859
- defaultMessage: [{
860
- "type": 0,
861
- "value": "An error occurred with your authentication. Please try again."
862
- }]
863
- }),
864
- onClose: resetErrorBoundary
865
- }));
866
- }, "ErrorFallback");
867
- var ErrorBoundary = /* @__PURE__ */__name(({
868
- children
869
- }) => {
870
- return /* @__PURE__ */React.createElement(import_react_error_boundary.ErrorBoundary, {
871
- FallbackComponent: ErrorFallback,
872
- onError: /* @__PURE__ */__name(error => {
873
- (0, import_logger.notify)({
874
- type: "error",
875
- title: "Authentication Error",
876
- message: error instanceof Error ? error.message : String(error)
877
- });
878
- }, "onError")
879
- }, children);
880
- }, "ErrorBoundary");
881
-
882
- // src/useAuthScreen.ts
883
- var React4 = __toESM(require("react"), 1);
884
- var useAuthScreen = /* @__PURE__ */__name(initialScreen => {
885
- const [screen, setScreen] = React4.useState(initialScreen || {
886
- value: "signIn"
887
- });
888
- return {
889
- screen,
890
- setScreen
891
- };
892
- }, "useAuthScreen");
893
-
894
- // src/Auth.tsx
895
- var AuthLogic = /* @__PURE__ */__name(props => {
896
- const {
897
- screen,
898
- setScreen,
899
- onSignUp,
900
- onForgotPassword,
901
- onSignIn,
902
- onConfirmSignUpCheckEmail,
903
- onConfirmSignUpWithCode,
904
- onForgotPasswordResetPassword,
905
- passwordMinimumLength,
906
- signUpTerms,
907
- maxForgotPasswordCodeLength
908
- } = props;
909
- const {
910
- clearNotifications,
911
- setLoading
912
- } = (0, import_react_notifications6.useNotifications)();
913
- React5.useEffect(() => {
914
- clearNotifications();
915
- }, [screen.value, clearNotifications]);
916
- React5.useEffect(() => {
917
- return clearNotifications;
918
- }, [clearNotifications]);
919
- const onGoToSignIn = /* @__PURE__ */__name(() => {
920
- setScreen({
921
- value: "signIn"
922
- });
923
- }, "onGoToSignIn");
924
- const onGoToSignUp = React5.useCallback(() => {
925
- if (!onSignUp) {
926
- return void 0;
927
- }
928
- setScreen({
929
- value: "signUp"
930
- });
931
- }, [onSignUp, setScreen]);
932
- const onGoToForgotPassword = React5.useCallback(() => {
933
- if (!onForgotPassword) {
934
- return void 0;
935
- }
936
- setScreen({
937
- value: "forgotPassword"
938
- });
939
- }, [onForgotPassword, setScreen]);
940
- const notificationsWrapper = /* @__PURE__ */__name(fn => {
941
- return async input => {
942
- if (fn) {
943
- clearNotifications();
944
- setLoading(true);
945
- const result = await fn(input);
946
- setLoading(false);
947
- return result;
948
- }
949
- };
950
- }, "notificationsWrapper");
951
- if (screen.value === "signIn") {
952
- return /* @__PURE__ */React5.createElement(AuthSignIn, {
953
- onSignIn: notificationsWrapper(onSignIn),
954
- onGoToSignUp: onSignUp && onGoToSignUp,
955
- onGoToForgotPassword: onForgotPassword && onGoToForgotPassword,
956
- passwordMinimumLength
957
- });
958
- }
959
- if (screen.value === "signUp" && onSignUp) {
960
- return /* @__PURE__ */React5.createElement(AuthSignUp, {
961
- onSignUp: notificationsWrapper(onSignUp),
962
- passwordMinimumLength,
963
- onGoToSignIn,
964
- signUpTerms
965
- });
966
- }
967
- if (screen.value === "forgotPassword" && onForgotPassword) {
968
- return /* @__PURE__ */React5.createElement(AuthForgotPassword, {
969
- onForgotPassword: notificationsWrapper(onForgotPassword),
970
- onGoToSignIn,
971
- onGoToSignUp: onSignUp && onGoToSignUp
972
- });
973
- }
974
- if (screen.value === "confirmResetPassword" && onForgotPasswordResetPassword) {
975
- return /* @__PURE__ */React5.createElement(AuthForgotPasswordResetPassword, {
976
- onForgotPasswordResetPassword: notificationsWrapper(onForgotPasswordResetPassword),
977
- onGoToSignIn,
978
- email: screen.context.email,
979
- maxCodeLength: maxForgotPasswordCodeLength
980
- });
981
- }
982
- if (screen.value === "confirmSignUpWithCode" && onConfirmSignUpWithCode) {
983
- return /* @__PURE__ */React5.createElement(AuthConfirmSignUpWithCode, {
984
- onConfirmSignUpWithCode: notificationsWrapper(onConfirmSignUpWithCode),
985
- email: screen.context.email
986
- });
987
- }
988
- if (screen.value === "confirmSignUpCheckEmail" && onConfirmSignUpCheckEmail) {
989
- return /* @__PURE__ */React5.createElement(AuthConfirmSignUpCheckEmail, {
990
- onConfirmSignUpCheckEmail
991
- });
992
- }
993
- return null;
994
- }, "AuthLogic");
995
- var Auth = /* @__PURE__ */__name(props => {
996
- const {
997
- layout = {
998
- fullScreen: true
999
- }
1000
- } = props;
1001
- const authScreenHook = useAuthScreen(props.initialScreen);
1002
- const screen = props.screen ?? authScreenHook.screen;
1003
- const setScreen = props.setScreen ?? authScreenHook.setScreen;
1004
- const withLogoNode = React5.useMemo(() => {
1005
- return /* @__PURE__ */React5.createElement(LogoProvider, {
1006
- logo: props.logo
1007
- }, /* @__PURE__ */React5.createElement(ErrorBoundary, null, /* @__PURE__ */React5.createElement(AuthLogic, {
1008
- screen,
1009
- setScreen,
1010
- signUpTerms: props.signUpTerms,
1011
- passwordMinimumLength: props.passwordMinimumLength,
1012
- maxForgotPasswordCodeLength: props.maxForgotPasswordCodeLength,
1013
- onSignIn: props.onSignIn,
1014
- onSignUp: props.onSignUp,
1015
- onConfirmSignUpCheckEmail: props.onConfirmSignUpCheckEmail,
1016
- onConfirmSignUpWithCode: props.onConfirmSignUpWithCode,
1017
- onForgotPassword: props.onForgotPassword,
1018
- onForgotPasswordResetPassword: props.onForgotPasswordResetPassword
1019
- })));
1020
- }, [props, screen, setScreen]);
1021
- if (layout.fullScreen) {
1022
- if (layout.sideContentPosition) {
1023
- return /* @__PURE__ */React5.createElement(AuthFullScreen, null, /* @__PURE__ */React5.createElement(import_ui7.Flex, {
1024
- sx: {
1025
- width: "100%",
1026
- height: "100%",
1027
- flexDirection: layout.sideContentPosition === "left" ? "row" : "row-reverse"
1028
- }
1029
- }, /* @__PURE__ */React5.createElement(import_ui7.Flex, {
1030
- sx: {
1031
- width: "100%",
1032
- height: "100%",
1033
- flex: [0, 0, 1],
1034
- justifyContent: "center",
1035
- alignItems: "center"
1036
- }
1037
- }, layout.sideContent), /* @__PURE__ */React5.createElement(import_ui7.Flex, {
1038
- sx: {
1039
- width: "100%",
1040
- height: "100%",
1041
- flex: [1],
1042
- justifyContent: "center",
1043
- alignItems: "center"
1044
- }
1045
- }, withLogoNode)));
1046
- }
1047
- return /* @__PURE__ */React5.createElement(AuthFullScreen, null, withLogoNode);
1048
- }
1049
- return withLogoNode;
1050
- }, "Auth");
1051
-
1052
- // src/AuthProvider.tsx
1053
- var import_react_notifications7 = require("@ttoss/react-notifications");
1054
- var React6 = __toESM(require("react"), 1);
1055
- var AuthContext = /* @__PURE__ */React6.createContext(null);
1056
- var UNAUTHENTICATED_USER = {
1057
- user: null,
1058
- tokens: null,
1059
- isAuthenticated: false
1060
- };
1061
- var AuthProvider = /* @__PURE__ */__name(props => {
1062
- const {
1063
- getAuthData,
1064
- signOut: signOutProp
1065
- } = props;
1066
- const {
1067
- setLoading
1068
- } = (0, import_react_notifications7.useNotifications)();
1069
- const [authData, setAuthData] = React6.useState({
1070
- user: null,
1071
- tokens: null,
1072
- isAuthenticated: void 0
1073
- });
1074
- React6.useEffect(() => {
1075
- setLoading(authData.isAuthenticated === void 0);
1076
- }, [authData.isAuthenticated, setLoading]);
1077
- React6.useEffect(() => {
1078
- const fetchAuthData = /* @__PURE__ */__name(async () => {
1079
- try {
1080
- const data = await getAuthData?.();
1081
- if (data) {
1082
- setAuthData(data);
1083
- } else {
1084
- setAuthData(UNAUTHENTICATED_USER);
1085
- }
1086
- } catch {
1087
- setAuthData(UNAUTHENTICATED_USER);
1088
- }
1089
- }, "fetchAuthData");
1090
- fetchAuthData();
1091
- }, [getAuthData]);
1092
- const signOut = React6.useCallback(async () => {
1093
- await signOutProp?.();
1094
- setAuthData(UNAUTHENTICATED_USER);
1095
- }, [signOutProp]);
1096
- if (authData.isAuthenticated === void 0) {
1097
- return null;
1098
- }
1099
- return /* @__PURE__ */React6.createElement(AuthContext.Provider, {
1100
- value: {
1101
- signOut,
1102
- isAuthenticated: authData.isAuthenticated ?? false,
1103
- user: authData.user,
1104
- tokens: authData.tokens,
1105
- setAuthData
1106
- }
1107
- }, props.children);
1108
- }, "AuthProvider");
1109
- var useAuth = /* @__PURE__ */__name(() => {
1110
- const context = React6.useContext(AuthContext);
1111
- if (!context) {
1112
- throw new Error("useAuth must be used within an AuthProvider");
1113
- }
1114
- return context;
1115
- }, "useAuth");
1116
- // Annotate the CommonJS export names for ESM import in node:
1117
- 0 && (module.exports = {
1118
- Auth,
1119
- AuthConfirmSignUpCheckEmail,
1120
- AuthConfirmSignUpWithCode,
1121
- AuthForgotPassword,
1122
- AuthForgotPasswordResetPassword,
1123
- AuthFullScreen,
1124
- AuthProvider,
1125
- AuthSignIn,
1126
- AuthSignUp,
1127
- ErrorBoundary,
1128
- useAuth,
1129
- useAuthScreen
1130
- });