@ttoss/react-auth-core 0.2.56 → 0.2.58

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 ADDED
@@ -0,0 +1,1099 @@
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 schema = import_forms3.yup.object().shape({
366
+ code: import_forms3.yup.string().required(intl.formatMessage({
367
+ id: "0XOzcH",
368
+ defaultMessage: [{
369
+ "type": 0,
370
+ "value": "Required field"
371
+ }]
372
+ })).max(6, intl.formatMessage({
373
+ id: "SfWKyS",
374
+ defaultMessage: [{
375
+ "type": 0,
376
+ "value": "Maximum "
377
+ }, {
378
+ "type": 1,
379
+ "value": "value"
380
+ }, {
381
+ "type": 0,
382
+ "value": " characters"
383
+ }]
384
+ }, {
385
+ value: 6
386
+ })),
387
+ newPassword: import_forms3.yup.string().required(intl.formatMessage({
388
+ id: "kdFYba",
389
+ defaultMessage: [{
390
+ "type": 0,
391
+ "value": "Password field is required"
392
+ }]
393
+ })).min(props.passwordMinimumLength || 8, intl.formatMessage({
394
+ id: "TZ4WUk",
395
+ defaultMessage: [{
396
+ "type": 0,
397
+ "value": "Password requires "
398
+ }, {
399
+ "type": 1,
400
+ "value": "value"
401
+ }, {
402
+ "type": 0,
403
+ "value": " characters"
404
+ }]
405
+ }, {
406
+ value: props.passwordMinimumLength || 8
407
+ })).trim()
408
+ });
409
+ const formMethods = (0, import_forms3.useForm)({
410
+ resolver: (0, import_forms3.yupResolver)(schema),
411
+ mode: "onChange"
412
+ });
413
+ return /* @__PURE__ */React.createElement(import_forms3.Form, {
414
+ ...formMethods,
415
+ sx: {
416
+ maxWidth: "390px"
417
+ },
418
+ onSubmit: /* @__PURE__ */__name(({
419
+ code,
420
+ newPassword
421
+ }) => {
422
+ return props.onForgotPasswordResetPassword({
423
+ email: props.email,
424
+ code,
425
+ newPassword
426
+ });
427
+ }, "onSubmit")
428
+ }, /* @__PURE__ */React.createElement(AuthCard, {
429
+ buttonLabel: intl.formatMessage({
430
+ id: "HT4tSM",
431
+ defaultMessage: [{
432
+ "type": 0,
433
+ "value": "Reset Password"
434
+ }]
435
+ }),
436
+ isValidForm: formMethods.formState.isValid,
437
+ title: intl.formatMessage({
438
+ id: "HT4tSM",
439
+ defaultMessage: [{
440
+ "type": 0,
441
+ "value": "Reset Password"
442
+ }]
443
+ }),
444
+ extraButton: props.onGoToSignIn ? /* @__PURE__ */React.createElement(import_ui3.Button, {
445
+ type: "button",
446
+ sx: {
447
+ textAlign: "center",
448
+ display: "initial"
449
+ },
450
+ variant: "secondary",
451
+ onClick: props.onGoToSignIn
452
+ }, intl.formatMessage({
453
+ id: "6PdOcy",
454
+ defaultMessage: [{
455
+ "type": 0,
456
+ "value": "Cancel"
457
+ }]
458
+ })) : null
459
+ }, /* @__PURE__ */React.createElement(import_forms3.FormFieldInput, {
460
+ name: "code",
461
+ label: intl.formatMessage({
462
+ id: "s1OmP0",
463
+ defaultMessage: [{
464
+ "type": 0,
465
+ "value": "Confirmation code"
466
+ }]
467
+ })
468
+ }), /* @__PURE__ */React.createElement(import_forms3.FormFieldPassword, {
469
+ name: "newPassword",
470
+ label: intl.formatMessage({
471
+ id: "e3IQoc",
472
+ defaultMessage: [{
473
+ "type": 0,
474
+ "value": "New Password"
475
+ }]
476
+ })
477
+ }), /* @__PURE__ */React.createElement(import_react_notifications3.NotificationsBox, null)));
478
+ }, "AuthForgotPasswordResetPassword");
479
+
480
+ // src/AuthFullScreen.tsx
481
+ var import_ui4 = require("@ttoss/ui");
482
+ var AuthFullScreen = /* @__PURE__ */__name(({
483
+ children
484
+ }) => {
485
+ return /* @__PURE__ */React.createElement(import_ui4.Flex, {
486
+ sx: {
487
+ height: "100vh",
488
+ width: "100vw",
489
+ justifyContent: "center",
490
+ alignItems: "center",
491
+ margin: 0,
492
+ backgroundPosition: "center",
493
+ backgroundRepeat: "no-repeat",
494
+ backgroundSize: "cover"
495
+ }
496
+ }, children);
497
+ }, "AuthFullScreen");
498
+
499
+ // src/AuthSignIn.tsx
500
+ var import_forms4 = require("@ttoss/forms");
501
+ var import_react_i18n5 = require("@ttoss/react-i18n");
502
+ var import_react_notifications4 = require("@ttoss/react-notifications");
503
+ var import_ui5 = require("@ttoss/ui");
504
+ var AuthSignIn = /* @__PURE__ */__name(({
505
+ onSignIn,
506
+ onGoToSignUp,
507
+ defaultValues,
508
+ onGoToForgotPassword,
509
+ passwordMinimumLength = 8
510
+ }) => {
511
+ const {
512
+ intl
513
+ } = (0, import_react_i18n5.useI18n)();
514
+ const schema = import_forms4.yup.object().shape({
515
+ email: import_forms4.yup.string().required(intl.formatMessage({
516
+ id: "d1YCuH",
517
+ defaultMessage: [{
518
+ "type": 0,
519
+ "value": "Enter your email address"
520
+ }]
521
+ })).email(intl.formatMessage({
522
+ id: "9cApwd",
523
+ defaultMessage: [{
524
+ "type": 0,
525
+ "value": "Please, insert a valid e-mail"
526
+ }]
527
+ })),
528
+ password: import_forms4.yup.string().required(intl.formatMessage({
529
+ id: "kdFYba",
530
+ defaultMessage: [{
531
+ "type": 0,
532
+ "value": "Password field is required"
533
+ }]
534
+ })).min(passwordMinimumLength, intl.formatMessage({
535
+ id: "TZ4WUk",
536
+ defaultMessage: [{
537
+ "type": 0,
538
+ "value": "Password requires "
539
+ }, {
540
+ "type": 1,
541
+ "value": "value"
542
+ }, {
543
+ "type": 0,
544
+ "value": " characters"
545
+ }]
546
+ }, {
547
+ value: passwordMinimumLength
548
+ })).trim()
549
+ });
550
+ const formMethods = (0, import_forms4.useForm)({
551
+ defaultValues,
552
+ mode: "onChange",
553
+ resolver: (0, import_forms4.yupResolver)(schema)
554
+ });
555
+ const onSubmitForm = /* @__PURE__ */__name(data => {
556
+ return onSignIn(data);
557
+ }, "onSubmitForm");
558
+ return /* @__PURE__ */React.createElement(import_forms4.Form, {
559
+ sx: {
560
+ maxWidth: "390px",
561
+ width: "100%"
562
+ },
563
+ ...formMethods,
564
+ onSubmit: onSubmitForm
565
+ }, /* @__PURE__ */React.createElement(AuthCard, {
566
+ title: intl.formatMessage({
567
+ id: "SQJto2",
568
+ defaultMessage: [{
569
+ "type": 0,
570
+ "value": "Sign in"
571
+ }]
572
+ }),
573
+ buttonLabel: intl.formatMessage({
574
+ id: "SQJto2",
575
+ defaultMessage: [{
576
+ "type": 0,
577
+ "value": "Sign in"
578
+ }]
579
+ }),
580
+ isValidForm: formMethods.formState.isValid,
581
+ extraButton: onGoToSignUp ? /* @__PURE__ */React.createElement(import_ui5.Button, {
582
+ type: "button",
583
+ variant: "secondary",
584
+ sx: {
585
+ textAlign: "center",
586
+ display: "initial"
587
+ },
588
+ onClick: onGoToSignUp
589
+ }, intl.formatMessage({
590
+ id: "EZ3YF2",
591
+ defaultMessage: [{
592
+ "type": 0,
593
+ "value": "Sign up"
594
+ }]
595
+ })) : null
596
+ }, /* @__PURE__ */React.createElement(import_ui5.Flex, {
597
+ sx: {
598
+ flexDirection: "column",
599
+ gap: "xl"
600
+ }
601
+ }, /* @__PURE__ */React.createElement(import_forms4.FormFieldInput, {
602
+ name: "email",
603
+ label: intl.formatMessage({
604
+ id: "5E12mO",
605
+ defaultMessage: [{
606
+ "type": 0,
607
+ "value": "Email"
608
+ }]
609
+ })
610
+ }), /* @__PURE__ */React.createElement(import_forms4.FormFieldPassword, {
611
+ name: "password",
612
+ label: intl.formatMessage({
613
+ id: "PylVqx",
614
+ defaultMessage: [{
615
+ "type": 0,
616
+ "value": "Password"
617
+ }]
618
+ })
619
+ })), onGoToForgotPassword && /* @__PURE__ */React.createElement(import_ui5.Flex, {
620
+ sx: {
621
+ justifyContent: "space-between",
622
+ marginTop: "lg"
623
+ }
624
+ }, /* @__PURE__ */React.createElement(import_ui5.Text, {
625
+ sx: {
626
+ marginLeft: "auto",
627
+ cursor: "pointer"
628
+ },
629
+ as: import_ui5.Link,
630
+ onClick: onGoToForgotPassword
631
+ }, intl.formatMessage({
632
+ id: "BtK6KR",
633
+ defaultMessage: [{
634
+ "type": 0,
635
+ "value": "Forgot password?"
636
+ }]
637
+ }))), /* @__PURE__ */React.createElement(import_react_notifications4.NotificationsBox, null)));
638
+ }, "AuthSignIn");
639
+
640
+ // src/AuthSignUp.tsx
641
+ var import_forms5 = require("@ttoss/forms");
642
+ var import_react_i18n6 = require("@ttoss/react-i18n");
643
+ var import_react_notifications5 = require("@ttoss/react-notifications");
644
+ var import_ui6 = require("@ttoss/ui");
645
+ var React3 = __toESM(require("react"), 1);
646
+ var AuthSignUp = /* @__PURE__ */__name(props => {
647
+ const {
648
+ intl
649
+ } = (0, import_react_i18n6.useI18n)();
650
+ const {
651
+ passwordMinimumLength = 8
652
+ } = props;
653
+ const schema = React3.useMemo(() => {
654
+ return import_forms5.yup.object().shape({
655
+ email: import_forms5.yup.string().required(intl.formatMessage({
656
+ id: "d1YCuH",
657
+ defaultMessage: [{
658
+ "type": 0,
659
+ "value": "Enter your email address"
660
+ }]
661
+ })).email(intl.formatMessage({
662
+ id: "OhDL0i",
663
+ defaultMessage: [{
664
+ "type": 0,
665
+ "value": "Invalid email"
666
+ }]
667
+ })),
668
+ password: import_forms5.yup.string().required(intl.formatMessage({
669
+ id: "kdFYba",
670
+ defaultMessage: [{
671
+ "type": 0,
672
+ "value": "Password field is required"
673
+ }]
674
+ })).min(passwordMinimumLength, intl.formatMessage({
675
+ id: "TZ4WUk",
676
+ defaultMessage: [{
677
+ "type": 0,
678
+ "value": "Password requires "
679
+ }, {
680
+ "type": 1,
681
+ "value": "value"
682
+ }, {
683
+ "type": 0,
684
+ "value": " characters"
685
+ }]
686
+ }, {
687
+ value: passwordMinimumLength
688
+ })).trim(),
689
+ confirmPassword: import_forms5.yup.string().required(intl.formatMessage({
690
+ id: "NJ57Qj",
691
+ defaultMessage: [{
692
+ "type": 0,
693
+ "value": "Confirm password field is required"
694
+ }]
695
+ })).oneOf([import_forms5.yup.ref("password")], intl.formatMessage({
696
+ id: "WU/CqP",
697
+ defaultMessage: [{
698
+ "type": 0,
699
+ "value": "Passwords are not the same"
700
+ }]
701
+ })),
702
+ signUpTerms: props.signUpTerms?.isRequired ? import_forms5.yup.boolean().required(intl.formatMessage({
703
+ id: "qnQYqN",
704
+ defaultMessage: [{
705
+ "type": 0,
706
+ "value": "You must accept the terms and conditions"
707
+ }]
708
+ })) : import_forms5.yup.boolean()
709
+ });
710
+ }, [intl, props.signUpTerms?.isRequired, passwordMinimumLength]);
711
+ const signUpTermsLabel = React3.useMemo(() => {
712
+ if (!props.signUpTerms) {
713
+ return null;
714
+ }
715
+ const signUpTermsFirstMessage = intl.formatMessage({
716
+ id: "Co3exe",
717
+ defaultMessage: [{
718
+ "type": 0,
719
+ "value": "By signing up, you agree to the following Terms and Conditions."
720
+ }]
721
+ });
722
+ const termsLinks = props.signUpTerms.terms.map((term, index, terms) => {
723
+ const finalPunctuation = index === terms.length - 1 ? "." : ", ";
724
+ return /* @__PURE__ */React3.createElement(React3.Fragment, {
725
+ key: index
726
+ }, /* @__PURE__ */React3.createElement(import_ui6.Link, {
727
+ key: index,
728
+ href: term.url,
729
+ target: "_blank",
730
+ rel: "noreferrer"
731
+ }, term.label), finalPunctuation);
732
+ });
733
+ const label = /* @__PURE__ */React3.createElement(import_ui6.Text, null, signUpTermsFirstMessage, " ", termsLinks);
734
+ return label;
735
+ }, [intl, props.signUpTerms]);
736
+ const signUpTermsNode = React3.useMemo(() => {
737
+ if (!props.signUpTerms) {
738
+ return null;
739
+ }
740
+ if (props.signUpTerms.isRequired) {
741
+ return /* @__PURE__ */React3.createElement(import_forms5.FormFieldCheckbox, {
742
+ name: "signUpTerms",
743
+ label: signUpTermsLabel
744
+ });
745
+ } else {
746
+ return /* @__PURE__ */React3.createElement(React3.Fragment, null, signUpTermsLabel);
747
+ }
748
+ }, [props.signUpTerms, signUpTermsLabel]);
749
+ const formMethods = (0, import_forms5.useForm)({
750
+ mode: "onChange",
751
+ resolver: (0, import_forms5.yupResolver)(schema)
752
+ });
753
+ const onSubmitForm = /* @__PURE__ */__name(data => {
754
+ return props.onSignUp(data);
755
+ }, "onSubmitForm");
756
+ return /* @__PURE__ */React3.createElement(import_forms5.Form, {
757
+ sx: {
758
+ maxWidth: "390px",
759
+ width: "100%"
760
+ },
761
+ ...formMethods,
762
+ onSubmit: onSubmitForm
763
+ }, /* @__PURE__ */React3.createElement(AuthCard, {
764
+ buttonLabel: intl.formatMessage({
765
+ id: "URJDrG",
766
+ defaultMessage: [{
767
+ "type": 0,
768
+ "value": "Sign up"
769
+ }]
770
+ }),
771
+ title: intl.formatMessage({
772
+ id: "oayEC3",
773
+ defaultMessage: [{
774
+ "type": 0,
775
+ "value": "Sign up"
776
+ }]
777
+ }),
778
+ isValidForm: formMethods.formState.isValid,
779
+ extraButton: /* @__PURE__ */React3.createElement(import_ui6.Text, {
780
+ sx: {
781
+ cursor: "pointer"
782
+ },
783
+ onClick: props.onGoToSignIn,
784
+ as: import_ui6.Link
785
+ }, intl.formatMessage({
786
+ id: "8GMUPk",
787
+ defaultMessage: [{
788
+ "type": 0,
789
+ "value": "I'm already registered"
790
+ }]
791
+ }))
792
+ }, /* @__PURE__ */React3.createElement(import_ui6.Flex, {
793
+ sx: {
794
+ flexDirection: "column",
795
+ gap: "xl"
796
+ }
797
+ }, /* @__PURE__ */React3.createElement(import_forms5.FormFieldInput, {
798
+ name: "email",
799
+ label: intl.formatMessage({
800
+ id: "5E12mO",
801
+ defaultMessage: [{
802
+ "type": 0,
803
+ "value": "Email"
804
+ }]
805
+ })
806
+ }), /* @__PURE__ */React3.createElement(import_forms5.FormFieldPassword, {
807
+ name: "password",
808
+ label: intl.formatMessage({
809
+ id: "PylVqx",
810
+ defaultMessage: [{
811
+ "type": 0,
812
+ "value": "Password"
813
+ }]
814
+ })
815
+ }), /* @__PURE__ */React3.createElement(import_forms5.FormFieldPassword, {
816
+ name: "confirmPassword",
817
+ label: intl.formatMessage({
818
+ id: "lY+cuM",
819
+ defaultMessage: [{
820
+ "type": 0,
821
+ "value": "Confirm password"
822
+ }]
823
+ })
824
+ }), signUpTermsNode), /* @__PURE__ */React3.createElement(import_react_notifications5.NotificationsBox, null)));
825
+ }, "AuthSignUp");
826
+
827
+ // src/ErrorBoundary.tsx
828
+ var import_NotificationCard3 = require("@ttoss/components/NotificationCard");
829
+ var import_logger = require("@ttoss/logger");
830
+ var import_react_i18n7 = require("@ttoss/react-i18n");
831
+ var React4 = __toESM(require("react"), 1);
832
+ var import_react_error_boundary = require("react-error-boundary");
833
+ var ErrorFallback = /* @__PURE__ */__name(({
834
+ resetErrorBoundary
835
+ }) => {
836
+ const {
837
+ intl
838
+ } = (0, import_react_i18n7.useI18n)();
839
+ return /* @__PURE__ */React4.createElement("div", {
840
+ role: "alert"
841
+ }, /* @__PURE__ */React4.createElement(import_NotificationCard3.NotificationCard, {
842
+ type: "error",
843
+ message: intl.formatMessage({
844
+ id: "khMx/2",
845
+ defaultMessage: [{
846
+ "type": 0,
847
+ "value": "An error occurred with your authentication. Please try again."
848
+ }]
849
+ }),
850
+ onClose: resetErrorBoundary
851
+ }));
852
+ }, "ErrorFallback");
853
+ var ErrorBoundary = /* @__PURE__ */__name(({
854
+ children
855
+ }) => {
856
+ return /* @__PURE__ */React4.createElement(import_react_error_boundary.ErrorBoundary, {
857
+ FallbackComponent: ErrorFallback,
858
+ onError: /* @__PURE__ */__name(error => {
859
+ (0, import_logger.notify)({
860
+ type: "error",
861
+ title: "Authentication Error",
862
+ message: error.message
863
+ });
864
+ }, "onError")
865
+ }, children);
866
+ }, "ErrorBoundary");
867
+
868
+ // src/Auth.tsx
869
+ var AuthLogic = /* @__PURE__ */__name(props => {
870
+ const {
871
+ screen,
872
+ setScreen,
873
+ onSignUp,
874
+ onForgotPassword,
875
+ onSignIn,
876
+ onConfirmSignUpCheckEmail,
877
+ onConfirmSignUpWithCode,
878
+ onForgotPasswordResetPassword,
879
+ passwordMinimumLength,
880
+ signUpTerms
881
+ } = props;
882
+ const {
883
+ clearNotifications,
884
+ setLoading
885
+ } = (0, import_react_notifications6.useNotifications)();
886
+ React5.useEffect(() => {
887
+ clearNotifications();
888
+ }, [screen.value, clearNotifications]);
889
+ React5.useEffect(() => {
890
+ return clearNotifications;
891
+ }, [clearNotifications]);
892
+ const onGoToSignIn = /* @__PURE__ */__name(() => {
893
+ setScreen({
894
+ value: "signIn"
895
+ });
896
+ }, "onGoToSignIn");
897
+ const onGoToSignUp = React5.useCallback(() => {
898
+ if (!onSignUp) {
899
+ return void 0;
900
+ }
901
+ setScreen({
902
+ value: "signUp"
903
+ });
904
+ }, [onSignUp, setScreen]);
905
+ const onGoToForgotPassword = React5.useCallback(() => {
906
+ if (!onForgotPassword) {
907
+ return void 0;
908
+ }
909
+ setScreen({
910
+ value: "forgotPassword"
911
+ });
912
+ }, [onForgotPassword, setScreen]);
913
+ const notificationsWrapper = /* @__PURE__ */__name(fn => {
914
+ return async input => {
915
+ if (fn) {
916
+ clearNotifications();
917
+ setLoading(true);
918
+ const result = await fn(input);
919
+ setLoading(false);
920
+ return result;
921
+ }
922
+ };
923
+ }, "notificationsWrapper");
924
+ if (screen.value === "signIn") {
925
+ return /* @__PURE__ */React5.createElement(AuthSignIn, {
926
+ onSignIn: notificationsWrapper(onSignIn),
927
+ onGoToSignUp: onSignUp && onGoToSignUp,
928
+ onGoToForgotPassword: onForgotPassword && onGoToForgotPassword,
929
+ passwordMinimumLength
930
+ });
931
+ }
932
+ if (screen.value === "signUp" && onSignUp) {
933
+ return /* @__PURE__ */React5.createElement(AuthSignUp, {
934
+ onSignUp: notificationsWrapper(onSignUp),
935
+ passwordMinimumLength,
936
+ onGoToSignIn,
937
+ signUpTerms
938
+ });
939
+ }
940
+ if (screen.value === "forgotPassword" && onForgotPassword) {
941
+ return /* @__PURE__ */React5.createElement(AuthForgotPassword, {
942
+ onForgotPassword: notificationsWrapper(onForgotPassword),
943
+ onGoToSignIn,
944
+ onGoToSignUp: onSignUp && onGoToSignUp
945
+ });
946
+ }
947
+ if (screen.value === "confirmResetPassword" && onForgotPasswordResetPassword) {
948
+ return /* @__PURE__ */React5.createElement(AuthForgotPasswordResetPassword, {
949
+ onForgotPasswordResetPassword: notificationsWrapper(onForgotPasswordResetPassword),
950
+ onGoToSignIn,
951
+ email: screen.context.email
952
+ });
953
+ }
954
+ if (screen.value === "confirmSignUpWithCode" && onConfirmSignUpWithCode) {
955
+ return /* @__PURE__ */React5.createElement(AuthConfirmSignUpWithCode, {
956
+ onConfirmSignUpWithCode: notificationsWrapper(onConfirmSignUpWithCode),
957
+ email: screen.context.email
958
+ });
959
+ }
960
+ if (screen.value === "confirmSignUpCheckEmail" && onConfirmSignUpCheckEmail) {
961
+ return /* @__PURE__ */React5.createElement(AuthConfirmSignUpCheckEmail, {
962
+ onConfirmSignUpCheckEmail
963
+ });
964
+ }
965
+ return null;
966
+ }, "AuthLogic");
967
+ var Auth = /* @__PURE__ */__name(props => {
968
+ const {
969
+ layout = {
970
+ fullScreen: true
971
+ }
972
+ } = props;
973
+ const withLogoNode = React5.useMemo(() => {
974
+ return /* @__PURE__ */React5.createElement(LogoProvider, {
975
+ logo: props.logo
976
+ }, /* @__PURE__ */React5.createElement(ErrorBoundary, null, /* @__PURE__ */React5.createElement(AuthLogic, props)));
977
+ }, [props]);
978
+ if (layout.fullScreen) {
979
+ if (layout.sideContentPosition) {
980
+ return /* @__PURE__ */React5.createElement(AuthFullScreen, null, /* @__PURE__ */React5.createElement(import_ui7.Flex, {
981
+ sx: {
982
+ width: "100%",
983
+ height: "100%",
984
+ flexDirection: layout.sideContentPosition === "left" ? "row" : "row-reverse"
985
+ }
986
+ }, /* @__PURE__ */React5.createElement(import_ui7.Flex, {
987
+ sx: {
988
+ width: "100%",
989
+ height: "100%",
990
+ flex: [0, 0, 1],
991
+ justifyContent: "center",
992
+ alignItems: "center"
993
+ }
994
+ }, layout.sideContent), /* @__PURE__ */React5.createElement(import_ui7.Flex, {
995
+ sx: {
996
+ width: "100%",
997
+ height: "100%",
998
+ flex: [1],
999
+ justifyContent: "center",
1000
+ alignItems: "center"
1001
+ }
1002
+ }, withLogoNode)));
1003
+ }
1004
+ return /* @__PURE__ */React5.createElement(AuthFullScreen, null, withLogoNode);
1005
+ }
1006
+ return withLogoNode;
1007
+ }, "Auth");
1008
+
1009
+ // src/AuthProvider.tsx
1010
+ var import_react_notifications7 = require("@ttoss/react-notifications");
1011
+ var React6 = __toESM(require("react"), 1);
1012
+ var AuthContext = /* @__PURE__ */React6.createContext(null);
1013
+ var UNAUTHENTICATED_USER = {
1014
+ user: null,
1015
+ tokens: null,
1016
+ isAuthenticated: false
1017
+ };
1018
+ var AuthProvider = /* @__PURE__ */__name(props => {
1019
+ const {
1020
+ getAuthData,
1021
+ signOut: signOutProp
1022
+ } = props;
1023
+ const {
1024
+ setLoading
1025
+ } = (0, import_react_notifications7.useNotifications)();
1026
+ const [authData, setAuthData] = React6.useState({
1027
+ user: null,
1028
+ tokens: null,
1029
+ isAuthenticated: void 0
1030
+ });
1031
+ React6.useEffect(() => {
1032
+ setLoading(authData.isAuthenticated === void 0);
1033
+ }, [authData.isAuthenticated, setLoading]);
1034
+ React6.useEffect(() => {
1035
+ const fetchAuthData = /* @__PURE__ */__name(async () => {
1036
+ try {
1037
+ const data = await getAuthData?.();
1038
+ if (data) {
1039
+ setAuthData(data);
1040
+ } else {
1041
+ setAuthData(UNAUTHENTICATED_USER);
1042
+ }
1043
+ } catch {
1044
+ setAuthData(UNAUTHENTICATED_USER);
1045
+ }
1046
+ }, "fetchAuthData");
1047
+ fetchAuthData();
1048
+ }, [getAuthData]);
1049
+ const signOut = React6.useCallback(async () => {
1050
+ await signOutProp?.();
1051
+ setAuthData(UNAUTHENTICATED_USER);
1052
+ }, [signOutProp]);
1053
+ if (authData.isAuthenticated === void 0) {
1054
+ return null;
1055
+ }
1056
+ return /* @__PURE__ */React6.createElement(AuthContext.Provider, {
1057
+ value: {
1058
+ signOut,
1059
+ isAuthenticated: authData.isAuthenticated ?? false,
1060
+ user: authData.user,
1061
+ tokens: authData.tokens,
1062
+ setAuthData
1063
+ }
1064
+ }, props.children);
1065
+ }, "AuthProvider");
1066
+ var useAuth = /* @__PURE__ */__name(() => {
1067
+ const context = React6.useContext(AuthContext);
1068
+ if (!context) {
1069
+ throw new Error("useAuth must be used within an AuthProvider");
1070
+ }
1071
+ return context;
1072
+ }, "useAuth");
1073
+
1074
+ // src/useAuthScreen.ts
1075
+ var React7 = __toESM(require("react"), 1);
1076
+ var useAuthScreen = /* @__PURE__ */__name(initialScreen => {
1077
+ const [screen, setScreen] = React7.useState(initialScreen || {
1078
+ value: "signIn"
1079
+ });
1080
+ return {
1081
+ screen,
1082
+ setScreen
1083
+ };
1084
+ }, "useAuthScreen");
1085
+ // Annotate the CommonJS export names for ESM import in node:
1086
+ 0 && (module.exports = {
1087
+ Auth,
1088
+ AuthConfirmSignUpCheckEmail,
1089
+ AuthConfirmSignUpWithCode,
1090
+ AuthForgotPassword,
1091
+ AuthForgotPasswordResetPassword,
1092
+ AuthFullScreen,
1093
+ AuthProvider,
1094
+ AuthSignIn,
1095
+ AuthSignUp,
1096
+ ErrorBoundary,
1097
+ useAuth,
1098
+ useAuthScreen
1099
+ });