@ttoss/react-auth-core 0.2.0

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