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