@gahojin-inc/amplify-auth-hooks 2025.8.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.
@@ -0,0 +1,1372 @@
1
+ import { assign, forwardTo, fromPromise, sendParent, setup } from "xstate";
2
+ import { autoSignIn, confirmResetPassword, confirmSignIn, confirmSignUp, confirmUserAttribute, fetchUserAttributes, getCurrentUser, resendSignUpCode, resetPassword, sendUserAttributeVerificationCode, signIn, signInWithRedirect, signOut, signUp } from "@aws-amplify/auth";
3
+
4
+ //#region src/machines/actions.ts
5
+ const setTotpSecretCode = ({ event }) => {
6
+ const { sharedSecret } = event.output?.nextStep?.totpSetupDetails ?? {};
7
+ return sharedSecret;
8
+ };
9
+ const setAllowedMfaTypes = ({ event }) => {
10
+ return event.output?.nextStep?.allowedMFATypes;
11
+ };
12
+ const setShouldVerifyUserAttributeStep = "SHOULD_CONFIRM_USER_ATTRIBUTE";
13
+ const setConfirmAttributeCompleteStep = "CONFIRM_ATTRIBUTE_COMPLETE";
14
+ const setConfirmSignUpStep = "CONFIRM_SIGN_UP";
15
+ const setNextSignInStep = ({ event }) => {
16
+ const output = event.output ?? {};
17
+ return output.nextStep?.signInStep === "DONE" ? "SIGN_IN_COMPLETE" : output.nextStep?.signInStep;
18
+ };
19
+ const setNextSignUpStep = ({ event }) => {
20
+ const output = event.output ?? {};
21
+ return output.nextStep?.signUpStep === "DONE" ? "SIGN_UP_COMPLETE" : output.nextStep?.signUpStep;
22
+ };
23
+ const setNextResetPasswordStep = ({ event }) => {
24
+ const output = event.output ?? {};
25
+ return output.nextStep?.resetPasswordStep === "DONE" ? "RESET_PASSWORD_COMPLETE" : output.nextStep?.resetPasswordStep;
26
+ };
27
+ const setRemoteError = ({ event }) => {
28
+ const error = event.error;
29
+ if (error?.name === "NoUserPoolError") return "Configuration error (see console) – please contact the administrator";
30
+ return error?.message || String(error);
31
+ };
32
+ const setUsername = ({ event }) => event.data?.username;
33
+ const setCodeDeliveryDetails = ({ event }) => {
34
+ const output = event.output;
35
+ if (output?.nextStep?.codeDeliveryDetails) return output?.nextStep?.codeDeliveryDetails;
36
+ return output;
37
+ };
38
+ const setUnverifiedUserAttributes = ({ event }) => {
39
+ const { email, phone_number } = event.output;
40
+ const unverifiedUserAttributes = {
41
+ ...email && { email },
42
+ ...phone_number && { phone_number }
43
+ };
44
+ return unverifiedUserAttributes;
45
+ };
46
+ const setSelectedUserAttribute = ({ event }) => {
47
+ const output = event?.output;
48
+ return output?.attributeName;
49
+ };
50
+
51
+ //#endregion
52
+ //#region src/machines/guards.ts
53
+ const SIGN_IN_STEP_MFA_CONFIRMATION = [
54
+ "CONFIRM_SIGN_IN_WITH_SMS_CODE",
55
+ "CONFIRM_SIGN_IN_WITH_TOTP_CODE",
56
+ "CONFIRM_SIGN_IN_WITH_EMAIL_CODE"
57
+ ];
58
+ const shouldConfirmSignInWithNewPassword = (event) => {
59
+ const output = event.output;
60
+ return output?.nextStep?.signInStep === "CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED";
61
+ };
62
+ const shouldResetPasswordFromSignIn = (event) => {
63
+ const output = event.output;
64
+ return output?.nextStep?.signInStep === "RESET_PASSWORD";
65
+ };
66
+ const shouldConfirmSignUpFromSignIn = (event) => {
67
+ const output = event.output;
68
+ return output?.nextStep?.signInStep === "CONFIRM_SIGN_UP";
69
+ };
70
+ const shouldAutoSignIn = (event) => {
71
+ const output = event.output;
72
+ return output?.nextStep?.signUpStep === "COMPLETE_AUTO_SIGN_IN";
73
+ };
74
+ const hasCompletedSignIn = (event) => {
75
+ const output = event.output;
76
+ return output?.nextStep?.signInStep === "DONE";
77
+ };
78
+ const hasCompletedSignUp = (event) => {
79
+ const output = event.output;
80
+ return output?.nextStep?.signUpStep === "DONE";
81
+ };
82
+ const hasCompletedResetPassword = (event) => {
83
+ const output = event.output;
84
+ return output?.nextStep?.resetPasswordStep === "DONE";
85
+ };
86
+ const hasCompletedAttributeConfirmation = (step) => {
87
+ return step === "CONFIRM_ATTRIBUTE_COMPLETE";
88
+ };
89
+ const isConfirmUserAttributeStep = (step) => {
90
+ return step === "CONFIRM_ATTRIBUTE_WITH_CODE";
91
+ };
92
+ const isShouldConfirmUserAttributeStep = (step) => {
93
+ return step === "SHOULD_CONFIRM_USER_ATTRIBUTE";
94
+ };
95
+ const isResetPasswordStep = (step) => {
96
+ return step === "RESET_PASSWORD";
97
+ };
98
+ const isConfirmSignUpStep = (step) => {
99
+ return step === "CONFIRM_SIGN_UP";
100
+ };
101
+ const isShouldConfirmSignInWithNewPassword = (step) => {
102
+ return step === "CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED";
103
+ };
104
+ const shouldConfirmSignIn = (step) => {
105
+ return SIGN_IN_STEP_MFA_CONFIRMATION.includes(step);
106
+ };
107
+ const shouldSetupTotp = (step) => {
108
+ return step === "CONTINUE_SIGN_IN_WITH_TOTP_SETUP";
109
+ };
110
+ const shouldSetupEmail = (step) => {
111
+ return step === "CONTINUE_SIGN_IN_WITH_EMAIL_SETUP";
112
+ };
113
+ const shouldSelectMfaType = (step) => {
114
+ return ["CONTINUE_SIGN_IN_WITH_MFA_SELECTION", "CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION"].includes(step);
115
+ };
116
+ const shouldResetPassword = (context, event) => {
117
+ const step = event?.input?.step ?? context.step;
118
+ return step === "RESET_PASSWORD";
119
+ };
120
+ const shouldConfirmResetPassword = (context, event) => {
121
+ const step = event?.input?.step ?? context.step;
122
+ return step === "CONFIRM_RESET_PASSWORD_WITH_CODE";
123
+ };
124
+ const shouldVerifyAttribute = (event) => {
125
+ const { email, phone_number, phone_number_verified, email_verified } = event.output ?? {};
126
+ if (!email && !phone_number) return false;
127
+ const emailVerified = email_verified === "true";
128
+ const phoneVerified = phone_number_verified === "true";
129
+ return !emailVerified && !phoneVerified;
130
+ };
131
+ const isUserAlreadyConfirmed = (event) => {
132
+ return event.error?.message === "User is already confirmed.";
133
+ };
134
+
135
+ //#endregion
136
+ //#region src/machines/signIn/actor.ts
137
+ /**
138
+ * @internal
139
+ */
140
+ const signInActor = (handlers, overridesContext) => {
141
+ return setup({
142
+ types: {
143
+ context: {},
144
+ events: {}
145
+ },
146
+ guards: {
147
+ shouldConfirmSignIn: ({ context: { step } }) => shouldConfirmSignIn(step),
148
+ shouldSetupTotp: ({ context: { step } }) => shouldSetupTotp(step),
149
+ shouldSetupEmail: ({ context: { step } }) => shouldSetupEmail(step),
150
+ shouldSelectMfaType: ({ context: { step } }) => shouldSelectMfaType(step),
151
+ shouldVerifyAttribute: ({ event }) => shouldVerifyAttribute(event),
152
+ shouldConfirmSignInWithNewPassword: ({ event }) => shouldConfirmSignInWithNewPassword(event),
153
+ shouldResetPasswordFromSignIn: ({ event }) => shouldResetPasswordFromSignIn(event),
154
+ shouldConfirmSignUpFromSignIn: ({ event }) => shouldConfirmSignUpFromSignIn(event),
155
+ hasCompletedSignIn: ({ event }) => hasCompletedSignIn(event),
156
+ isShouldConfirmSignInWithNewPassword: ({ context: { step } }) => isShouldConfirmSignInWithNewPassword(step)
157
+ },
158
+ actors: {
159
+ fetchUserAttributes: fromPromise(() => handlers.fetchUserAttributes()),
160
+ resetPassword: fromPromise(({ input }) => handlers.resetPassword(input)),
161
+ resendSignUpCode: fromPromise(({ input }) => handlers.resendSignUpCode(input)),
162
+ signIn: fromPromise(({ input }) => handlers.signIn(input)),
163
+ confirmSignIn: fromPromise(({ input }) => handlers.confirmSignIn(input)),
164
+ signInWithRedirect: fromPromise(({ input }) => handlers.signInWithRedirect(input))
165
+ },
166
+ actions: {
167
+ sendUpdate: sendParent({ type: "CHILD_CHANGED" }),
168
+ setShouldVerifyUserAttributeStep: assign({ step: setShouldVerifyUserAttributeStep }),
169
+ setUnverifiedUserAttributes: assign({ unverifiedUserAttributes: setUnverifiedUserAttributes }),
170
+ setCodeDeliveryDetails: assign({ codeDeliveryDetails: setCodeDeliveryDetails }),
171
+ setConfirmAttributeCompleteStep: assign({ step: "CONFIRM_ATTRIBUTE_COMPLETE" }),
172
+ setTotpSecretCode: assign({ totpSecretCode: setTotpSecretCode }),
173
+ setAllowedMfaTypes: assign({ allowedMfaTypes: setAllowedMfaTypes }),
174
+ setNextSignInStep: assign({ step: setNextSignInStep }),
175
+ setConfirmSignUpStep: assign({ step: setConfirmSignUpStep }),
176
+ setActorDoneData: assign(({ event }) => {
177
+ const output = event?.output ?? {};
178
+ return {
179
+ codeDeliveryDetails: output.codeDeliveryDetails,
180
+ missingAttributes: output.missingAttributes,
181
+ remoteError: output.remoteError,
182
+ username: output.username,
183
+ step: output.step,
184
+ totpSecretCode: output.totpSecretCode,
185
+ unverifiedUserAttributes: output.unverifiedUserAttributes,
186
+ allowedMfaTypes: output.allowedMfaTypes
187
+ };
188
+ }),
189
+ setUsername: assign({ username: setUsername }),
190
+ setRemoteError: assign({ remoteError: setRemoteError }),
191
+ clearError: assign({ remoteError: void 0 })
192
+ }
193
+ }).createMachine({
194
+ id: "signInActor",
195
+ context: ({ input }) => ({
196
+ step: "SIGN_IN",
197
+ ...overridesContext,
198
+ ...input
199
+ }),
200
+ initial: "init",
201
+ states: {
202
+ init: { always: [
203
+ {
204
+ guard: "shouldConfirmSignIn",
205
+ target: "#signInActor.confirmSignIn"
206
+ },
207
+ {
208
+ guard: "shouldSetupTotp",
209
+ target: "#signInActor.setupTotp"
210
+ },
211
+ {
212
+ guard: "shouldSetupEmail",
213
+ target: "#signInActor.setupEmail"
214
+ },
215
+ {
216
+ guard: "shouldSelectMfaType",
217
+ target: "#signInActor.selectMfaType"
218
+ },
219
+ {
220
+ guard: "isShouldConfirmSignInWithNewPassword",
221
+ actions: "setActorDoneData",
222
+ target: "#signInActor.forceChangePassword"
223
+ },
224
+ { target: "#signInActor.signIn" }
225
+ ] },
226
+ federatedSignIn: {
227
+ entry: ["sendUpdate", "clearError"],
228
+ invoke: {
229
+ src: "signInWithRedirect",
230
+ input: ({ event }) => event.data,
231
+ onDone: { target: "#signInActor.signIn" },
232
+ onError: {
233
+ actions: "setRemoteError",
234
+ target: "#signInActor.signIn"
235
+ }
236
+ }
237
+ },
238
+ fetchUserAttributes: { invoke: {
239
+ src: "fetchUserAttributes",
240
+ onDone: [{
241
+ guard: "shouldVerifyAttribute",
242
+ actions: ["setShouldVerifyUserAttributeStep", "setUnverifiedUserAttributes"],
243
+ target: "#signInActor.resolved"
244
+ }, {
245
+ actions: "setConfirmAttributeCompleteStep",
246
+ target: "#signInActor.resolved"
247
+ }],
248
+ onError: {
249
+ actions: "setConfirmAttributeCompleteStep",
250
+ target: "#signInActor.resolved"
251
+ }
252
+ } },
253
+ resendSignUpCode: {
254
+ tags: "pending",
255
+ invoke: {
256
+ src: "resendSignUpCode",
257
+ input: ({ context: { username }, event }) => ({
258
+ username,
259
+ ...event.data
260
+ }),
261
+ onDone: {
262
+ actions: "setCodeDeliveryDetails",
263
+ target: "#signInActor.resolved"
264
+ },
265
+ onError: {
266
+ actions: "setRemoteError",
267
+ target: "#signInActor.signIn"
268
+ }
269
+ }
270
+ },
271
+ resetPassword: { invoke: {
272
+ src: "resetPassword",
273
+ input: ({ context: { username }, event }) => ({
274
+ username,
275
+ ...event.data
276
+ }),
277
+ onDone: {
278
+ actions: "setCodeDeliveryDetails",
279
+ target: "#signInActor.resolved"
280
+ },
281
+ onError: { actions: ["setRemoteError", "sendUpdate"] }
282
+ } },
283
+ signIn: {
284
+ initial: "idle",
285
+ states: {
286
+ idle: {
287
+ entry: "sendUpdate",
288
+ on: {
289
+ FEDERATED_SIGN_IN: { target: "#signInActor.federatedSignIn" },
290
+ SUBMIT: { target: "submit" }
291
+ }
292
+ },
293
+ submit: {
294
+ tags: "pending",
295
+ entry: [
296
+ "sendUpdate",
297
+ "setUsername",
298
+ "clearError"
299
+ ],
300
+ invoke: {
301
+ src: "signIn",
302
+ input: ({ event }) => event.data,
303
+ onDone: [
304
+ {
305
+ guard: "hasCompletedSignIn",
306
+ actions: "setNextSignInStep",
307
+ target: "#signInActor.fetchUserAttributes"
308
+ },
309
+ {
310
+ guard: "shouldConfirmSignInWithNewPassword",
311
+ actions: "setNextSignInStep",
312
+ target: "#signInActor.forceChangePassword"
313
+ },
314
+ {
315
+ guard: "shouldResetPasswordFromSignIn",
316
+ actions: "setNextSignInStep",
317
+ target: "#signInActor.resetPassword"
318
+ },
319
+ {
320
+ guard: "shouldConfirmSignUpFromSignIn",
321
+ actions: "setNextSignInStep",
322
+ target: "#signInActor.resendSignUpCode"
323
+ },
324
+ {
325
+ actions: [
326
+ "setNextSignInStep",
327
+ "setTotpSecretCode",
328
+ "setAllowedMfaTypes"
329
+ ],
330
+ target: "#signInActor.init"
331
+ }
332
+ ],
333
+ onError: [{
334
+ guard: "shouldConfirmSignUpFromSignIn",
335
+ actions: "setConfirmSignUpStep",
336
+ target: "#signInActor.resendSignUpCode"
337
+ }, {
338
+ actions: "setRemoteError",
339
+ target: "idle"
340
+ }]
341
+ }
342
+ }
343
+ }
344
+ },
345
+ confirmSignIn: {
346
+ initial: "idle",
347
+ exit: "clearError",
348
+ states: {
349
+ idle: {
350
+ entry: "sendUpdate",
351
+ on: {
352
+ SUBMIT: { target: "submit" },
353
+ SIGN_IN: { target: "#signInActor.signIn" }
354
+ }
355
+ },
356
+ submit: {
357
+ tags: "pending",
358
+ entry: ["sendUpdate", "clearError"],
359
+ invoke: {
360
+ src: "confirmSignIn",
361
+ input: ({ event }) => event.data,
362
+ onDone: [
363
+ {
364
+ guard: "hasCompletedSignIn",
365
+ actions: "setNextSignInStep",
366
+ target: "#signInActor.fetchUserAttributes"
367
+ },
368
+ {
369
+ guard: "shouldConfirmSignInWithNewPassword",
370
+ actions: "setNextSignInStep",
371
+ target: "#signInActor.forceChangePassword"
372
+ },
373
+ {
374
+ guard: "shouldResetPasswordFromSignIn",
375
+ actions: "setNextSignInStep",
376
+ target: "#signInActor.resetPassword"
377
+ },
378
+ {
379
+ guard: "shouldConfirmSignUpFromSignIn",
380
+ actions: "setNextSignInStep",
381
+ target: "#signInActor.resendSignUpCode"
382
+ },
383
+ {
384
+ actions: [
385
+ "setNextSignInStep",
386
+ "setTotpSecretCode",
387
+ "setAllowedMfaTypes"
388
+ ],
389
+ target: "#signInActor.init"
390
+ }
391
+ ],
392
+ onError: {
393
+ actions: "setRemoteError",
394
+ target: "idle"
395
+ }
396
+ }
397
+ }
398
+ }
399
+ },
400
+ forceChangePassword: {
401
+ initial: "idle",
402
+ entry: "clearError",
403
+ exit: "clearError",
404
+ states: {
405
+ idle: {
406
+ entry: "sendUpdate",
407
+ on: { SUBMIT: { target: "submit" } }
408
+ },
409
+ submit: {
410
+ tags: "pending",
411
+ entry: ["sendUpdate", "clearError"],
412
+ invoke: {
413
+ src: "confirmSignIn",
414
+ input: ({ event }) => event.data,
415
+ onDone: [
416
+ {
417
+ guard: "hasCompletedSignIn",
418
+ actions: "setNextSignInStep",
419
+ target: "#signInActor.fetchUserAttributes"
420
+ },
421
+ {
422
+ guard: "shouldConfirmSignInWithNewPassword",
423
+ actions: "setNextSignInStep",
424
+ target: "#signInActor.forceChangePassword"
425
+ },
426
+ {
427
+ guard: "shouldResetPasswordFromSignIn",
428
+ actions: "setNextSignInStep",
429
+ target: "#signInActor.resetPassword"
430
+ },
431
+ {
432
+ guard: "shouldConfirmSignUpFromSignIn",
433
+ actions: "setNextSignInStep",
434
+ target: "#signInActor.resendSignUpCode"
435
+ },
436
+ {
437
+ actions: [
438
+ "setNextSignInStep",
439
+ "setTotpSecretCode",
440
+ "setAllowedMfaTypes"
441
+ ],
442
+ target: "#signInActor.init"
443
+ }
444
+ ],
445
+ onError: {
446
+ actions: "setRemoteError",
447
+ target: "idle"
448
+ }
449
+ }
450
+ }
451
+ }
452
+ },
453
+ setupTotp: {
454
+ initial: "idle",
455
+ exit: "clearError",
456
+ states: {
457
+ idle: {
458
+ entry: "sendUpdate",
459
+ on: {
460
+ SUBMIT: { target: "submit" },
461
+ SIGN_IN: { target: "#signInActor.signIn" }
462
+ }
463
+ },
464
+ submit: {
465
+ tags: "pending",
466
+ entry: ["sendUpdate", "clearError"],
467
+ invoke: {
468
+ src: "confirmSignIn",
469
+ input: ({ event }) => event.data,
470
+ onDone: [
471
+ {
472
+ guard: "hasCompletedSignIn",
473
+ actions: "setNextSignInStep",
474
+ target: "#signInActor.fetchUserAttributes"
475
+ },
476
+ {
477
+ guard: "shouldConfirmSignInWithNewPassword",
478
+ actions: "setNextSignInStep",
479
+ target: "#signInActor.forceChangePassword"
480
+ },
481
+ {
482
+ guard: "shouldResetPasswordFromSignIn",
483
+ actions: "setNextSignInStep",
484
+ target: "#signInActor.resetPassword"
485
+ },
486
+ {
487
+ guard: "shouldConfirmSignUpFromSignIn",
488
+ actions: "setNextSignInStep",
489
+ target: "#signInActor.resendSignUpCode"
490
+ },
491
+ {
492
+ actions: [
493
+ "setNextSignInStep",
494
+ "setTotpSecretCode",
495
+ "setAllowedMfaTypes"
496
+ ],
497
+ target: "#signInActor.init"
498
+ }
499
+ ],
500
+ onError: {
501
+ actions: "setRemoteError",
502
+ target: "idle"
503
+ }
504
+ }
505
+ }
506
+ }
507
+ },
508
+ setupEmail: {
509
+ initial: "idle",
510
+ exit: "clearError",
511
+ states: {
512
+ idle: {
513
+ entry: "sendUpdate",
514
+ on: {
515
+ SUBMIT: { target: "submit" },
516
+ SIGN_IN: { target: "#signInActor.signIn" }
517
+ }
518
+ },
519
+ submit: {
520
+ tags: "pending",
521
+ entry: ["sendUpdate", "clearError"],
522
+ invoke: {
523
+ src: "confirmSignIn",
524
+ input: ({ event }) => event.data,
525
+ onDone: [
526
+ {
527
+ guard: "hasCompletedSignIn",
528
+ actions: "setNextSignInStep",
529
+ target: "#signInActor.fetchUserAttributes"
530
+ },
531
+ {
532
+ guard: "shouldConfirmSignInWithNewPassword",
533
+ actions: "setNextSignInStep",
534
+ target: "#signInActor.forceChangePassword"
535
+ },
536
+ {
537
+ guard: "shouldResetPasswordFromSignIn",
538
+ actions: "setNextSignInStep",
539
+ target: "#signInActor.resetPassword"
540
+ },
541
+ {
542
+ guard: "shouldConfirmSignUpFromSignIn",
543
+ actions: "setNextSignInStep",
544
+ target: "#signInActor.resendSignUpCode"
545
+ },
546
+ {
547
+ actions: [
548
+ "setNextSignInStep",
549
+ "setTotpSecretCode",
550
+ "setAllowedMfaTypes"
551
+ ],
552
+ target: "#signInActor.init"
553
+ }
554
+ ],
555
+ onError: {
556
+ actions: "setRemoteError",
557
+ target: "idle"
558
+ }
559
+ }
560
+ }
561
+ }
562
+ },
563
+ selectMfaType: {
564
+ initial: "idle",
565
+ exit: "clearError",
566
+ states: {
567
+ idle: {
568
+ entry: "sendUpdate",
569
+ on: {
570
+ SUBMIT: { target: "submit" },
571
+ SIGN_IN: { target: "#signInActor.signIn" }
572
+ }
573
+ },
574
+ submit: {
575
+ tags: "pending",
576
+ entry: ["sendUpdate", "clearError"],
577
+ invoke: {
578
+ src: "confirmSignIn",
579
+ input: ({ event }) => event.data,
580
+ onDone: [
581
+ {
582
+ guard: "hasCompletedSignIn",
583
+ actions: "setNextSignInStep",
584
+ target: "#signInActor.fetchUserAttributes"
585
+ },
586
+ {
587
+ guard: "shouldConfirmSignInWithNewPassword",
588
+ actions: "setNextSignInStep",
589
+ target: "#signInActor.forceChangePassword"
590
+ },
591
+ {
592
+ guard: "shouldResetPasswordFromSignIn",
593
+ actions: "setNextSignInStep",
594
+ target: "#signInActor.resetPassword"
595
+ },
596
+ {
597
+ guard: "shouldConfirmSignUpFromSignIn",
598
+ actions: "setNextSignInStep",
599
+ target: "#signInActor.resendSignUpCode"
600
+ },
601
+ {
602
+ actions: [
603
+ "setNextSignInStep",
604
+ "setTotpSecretCode",
605
+ "setAllowedMfaTypes"
606
+ ],
607
+ target: "#signInActor.init"
608
+ }
609
+ ],
610
+ onError: {
611
+ actions: "setRemoteError",
612
+ target: "idle"
613
+ }
614
+ }
615
+ }
616
+ }
617
+ },
618
+ resolved: { type: "final" }
619
+ },
620
+ output: ({ context }) => context
621
+ });
622
+ };
623
+
624
+ //#endregion
625
+ //#region src/machines/defaultHandlers.ts
626
+ const defaultHandlers = {
627
+ getCurrentUser,
628
+ fetchUserAttributes,
629
+ signIn,
630
+ signInWithRedirect,
631
+ signUp,
632
+ signOut,
633
+ autoSignIn,
634
+ confirmSignIn,
635
+ confirmSignUp,
636
+ confirmResetPassword,
637
+ confirmUserAttribute,
638
+ resetPassword,
639
+ resendSignUpCode,
640
+ sendUserAttributeVerificationCode
641
+ };
642
+
643
+ //#endregion
644
+ //#region src/machines/forgotPassword/actor.ts
645
+ /**
646
+ * @internal
647
+ */
648
+ const forgotPasswordActor = (handlers, overridesContext) => {
649
+ return setup({
650
+ types: {
651
+ context: {},
652
+ events: {}
653
+ },
654
+ guards: {
655
+ shouldResetPassword: ({ context, event }) => shouldResetPassword(context, event),
656
+ shouldConfirmResetPassword: ({ context, event }) => shouldConfirmResetPassword(context, event),
657
+ hasCompletedResetPassword: ({ event }) => hasCompletedResetPassword(event)
658
+ },
659
+ actors: {
660
+ resetPassword: fromPromise(({ input }) => handlers.resetPassword(input)),
661
+ confirmResetPassword: fromPromise(({ input }) => handlers.confirmResetPassword(input))
662
+ },
663
+ actions: {
664
+ sendUpdate: sendParent({ type: "CHILD_CHANGED" }),
665
+ setCodeDeliveryDetails: assign({ codeDeliveryDetails: setCodeDeliveryDetails }),
666
+ setNextResetPasswordStep: assign({ step: setNextResetPasswordStep }),
667
+ setSignInStep: assign({ step: setNextSignInStep }),
668
+ setUsername: assign({ username: setUsername }),
669
+ setRemoteError: assign({ remoteError: setRemoteError }),
670
+ clearError: assign({ remoteError: void 0 })
671
+ }
672
+ }).createMachine({
673
+ id: "forgotPasswordActor",
674
+ initial: "init",
675
+ context: ({ input }) => ({
676
+ step: "FORGOT_PASSWORD",
677
+ ...overridesContext,
678
+ ...input
679
+ }),
680
+ states: {
681
+ init: { always: [
682
+ {
683
+ guard: "shouldResetPassword",
684
+ target: "#forgotPasswordActor.confirmResetPassword"
685
+ },
686
+ {
687
+ guard: "shouldConfirmResetPassword",
688
+ target: "#forgotPasswordActor.confirmResetPassword"
689
+ },
690
+ { target: "#forgotPasswordActor.forgotPassword" }
691
+ ] },
692
+ forgotPassword: {
693
+ initial: "idle",
694
+ exit: "clearError",
695
+ states: {
696
+ idle: {
697
+ entry: "sendUpdate",
698
+ on: { SUBMIT: { target: "submit" } }
699
+ },
700
+ submit: {
701
+ tags: "pending",
702
+ entry: [
703
+ "sendUpdate",
704
+ "setUsername",
705
+ "clearError"
706
+ ],
707
+ invoke: {
708
+ src: "resetPassword",
709
+ input: ({ context: { username } }) => ({ username }),
710
+ onDone: [{
711
+ actions: ["setCodeDeliveryDetails", "setNextResetPasswordStep"],
712
+ target: "#forgotPasswordActor.confirmResetPassword"
713
+ }],
714
+ onError: {
715
+ actions: "setRemoteError",
716
+ target: "idle"
717
+ }
718
+ }
719
+ }
720
+ }
721
+ },
722
+ confirmResetPassword: {
723
+ initial: "idle",
724
+ exit: "clearError",
725
+ states: {
726
+ idle: {
727
+ entry: "sendUpdate",
728
+ on: {
729
+ SUBMIT: { target: "submit" },
730
+ RESEND: { target: "resendCode" }
731
+ }
732
+ },
733
+ resendCode: {
734
+ tags: "pending",
735
+ entry: ["sendUpdate", "clearError"],
736
+ invoke: {
737
+ src: "resetPassword",
738
+ input: ({ context: { username } }) => ({ username }),
739
+ onDone: { target: "idle" },
740
+ onError: {
741
+ actions: "setRemoteError",
742
+ target: "idle"
743
+ }
744
+ }
745
+ },
746
+ submit: {
747
+ tags: "pending",
748
+ entry: ["sendUpdate", "clearError"],
749
+ invoke: {
750
+ src: "confirmResetPassword",
751
+ input: ({ context, event }) => ({
752
+ username: context.username,
753
+ ...event.data
754
+ }),
755
+ onDone: [{
756
+ guard: "hasCompletedResetPassword",
757
+ actions: "setNextResetPasswordStep",
758
+ target: "#forgotPasswordActor.resolved"
759
+ }, {
760
+ actions: "setSignInStep",
761
+ target: "#forgotPasswordActor.resolved"
762
+ }],
763
+ onError: {
764
+ actions: "setRemoteError",
765
+ target: "idle"
766
+ }
767
+ }
768
+ }
769
+ }
770
+ },
771
+ resolved: { type: "final" }
772
+ },
773
+ output: ({ context }) => context
774
+ });
775
+ };
776
+
777
+ //#endregion
778
+ //#region src/machines/signOut/actor.ts
779
+ /**
780
+ * @internal
781
+ */
782
+ const signOutActor = (handlers) => {
783
+ return setup({
784
+ types: { context: {} },
785
+ actors: { signOut: fromPromise(() => handlers.signOut()) }
786
+ }).createMachine({
787
+ id: "signOutActor",
788
+ initial: "pending",
789
+ context: {},
790
+ states: {
791
+ pending: {
792
+ tags: "pending",
793
+ invoke: {
794
+ src: "signOut",
795
+ onDone: "resolved",
796
+ onError: "rejected"
797
+ }
798
+ },
799
+ resolved: { type: "final" },
800
+ rejected: { type: "final" }
801
+ },
802
+ output: ({ context }) => context
803
+ });
804
+ };
805
+
806
+ //#endregion
807
+ //#region src/machines/signUp/actor.ts
808
+ /**
809
+ * @internal
810
+ */
811
+ const signUpActor = (handlers, overridesContext) => {
812
+ return setup({
813
+ types: {
814
+ context: {},
815
+ events: {}
816
+ },
817
+ guards: {
818
+ hasCompletedSignIn: ({ event }) => hasCompletedSignIn(event),
819
+ hasCompletedSignUp: ({ event }) => hasCompletedSignUp(event),
820
+ isUserAlreadyConfirmed: ({ event }) => isUserAlreadyConfirmed(event),
821
+ shouldAutoSignIn: ({ event }) => shouldAutoSignIn(event),
822
+ shouldConfirmSignInWithNewPassword: ({ event }) => shouldConfirmSignInWithNewPassword(event),
823
+ shouldConfirmSignUp: ({ context: { step } }) => step === "CONFIRM_SIGN_UP",
824
+ shouldConfirmSignUpFromSignIn: ({ event }) => shouldConfirmSignUpFromSignIn(event),
825
+ shouldResetPasswordFromSignIn: ({ event }) => shouldResetPasswordFromSignIn(event),
826
+ shouldVerifyAttribute: ({ event }) => shouldVerifyAttribute(event)
827
+ },
828
+ actors: {
829
+ autoSignIn: fromPromise(() => handlers.autoSignIn()),
830
+ confirmSignUp: fromPromise(({ input }) => handlers.confirmSignUp(input)),
831
+ fetchUserAttributes: fromPromise(() => handlers.fetchUserAttributes()),
832
+ resetPassword: fromPromise(({ input }) => handlers.resetPassword(input)),
833
+ resendSignUpCode: fromPromise(({ input }) => handlers.resendSignUpCode(input)),
834
+ signUp: fromPromise(({ input }) => handlers.signUp(input)),
835
+ signInWithRedirect: fromPromise(({ input }) => handlers.signInWithRedirect(input))
836
+ },
837
+ actions: {
838
+ sendUpdate: sendParent({ type: "CHILD_CHANGED" }),
839
+ setShouldVerifyUserAttributeStep: assign({ unverifiedUserAttributes: setUnverifiedUserAttributes }),
840
+ setConfirmAttributeCompleteStep: assign({ step: "CONFIRM_ATTRIBUTE_COMPLETE" }),
841
+ setCodeDeliveryDetails: assign({ codeDeliveryDetails: setCodeDeliveryDetails }),
842
+ setNextSignUpStep: assign({ step: setNextSignUpStep }),
843
+ setUsername: assign({ username: setUsername }),
844
+ setRemoteError: assign({ remoteError: setRemoteError }),
845
+ clearError: assign({ remoteError: void 0 })
846
+ }
847
+ }).createMachine({
848
+ id: "signUpActor",
849
+ initial: "init",
850
+ context: ({ input }) => ({
851
+ step: "SIGN_UP",
852
+ ...overridesContext,
853
+ ...input
854
+ }),
855
+ states: {
856
+ init: { always: [{
857
+ guard: "shouldConfirmSignUp",
858
+ target: "confirmSignUp"
859
+ }, { target: "#signUpActor.signUp" }] },
860
+ autoSignIn: {
861
+ tags: "pending",
862
+ invoke: {
863
+ src: "autoSignIn",
864
+ onDone: [
865
+ {
866
+ guard: "hasCompletedSignIn",
867
+ target: "#signUpActor.fetchUserAttributes"
868
+ },
869
+ {
870
+ guard: "shouldConfirmSignInWithNewPassword",
871
+ target: "#signUpActor.resolved"
872
+ },
873
+ {
874
+ guard: "shouldResetPasswordFromSignIn",
875
+ target: "#signUpActor.resetPassword"
876
+ },
877
+ {
878
+ guard: "shouldConfirmSignUpFromSignIn",
879
+ target: "#signUpActor.resendSignUpCode"
880
+ },
881
+ { target: "#signUpActor.resolved" }
882
+ ],
883
+ onError: { target: "#signUpActor.resolved" }
884
+ }
885
+ },
886
+ fetchUserAttributes: { invoke: {
887
+ src: "fetchUserAttributes",
888
+ onDone: [{
889
+ guard: "shouldVerifyAttribute",
890
+ actions: ["setShouldVerifyUserAttributeStep", "setConfirmAttributeCompleteStep"],
891
+ target: "#signUpActor.resolved"
892
+ }, {
893
+ actions: "setConfirmAttributeCompleteStep",
894
+ target: "#signUpActor.resolved"
895
+ }],
896
+ onError: {
897
+ actions: "setConfirmAttributeCompleteStep",
898
+ target: "#signUpActor.resolved"
899
+ }
900
+ } },
901
+ federatedSignIn: {
902
+ entry: ["sendUpdate", "clearError"],
903
+ invoke: {
904
+ src: "signInWithRedirect",
905
+ input: ({ event }) => event.data,
906
+ onDone: "signUp",
907
+ onError: {
908
+ actions: "setRemoteError",
909
+ target: "#signUpActor.signUp"
910
+ }
911
+ }
912
+ },
913
+ resetPassword: { invoke: {
914
+ src: "resetPassword",
915
+ input: ({ event }) => event.data,
916
+ onDone: {
917
+ actions: "setCodeDeliveryDetails",
918
+ target: "#signUpActor.resolved"
919
+ },
920
+ onError: { actions: "setRemoteError" }
921
+ } },
922
+ resendSignUpCode: {
923
+ tags: "pending",
924
+ entry: "sendUpdate",
925
+ exit: "sendUpdate",
926
+ invoke: {
927
+ src: "resendSignUpCode",
928
+ input: ({ context: { username }, event }) => ({
929
+ username,
930
+ ...event.data
931
+ }),
932
+ onDone: {
933
+ actions: "setCodeDeliveryDetails",
934
+ target: "#signUpActor.confirmSignUp"
935
+ },
936
+ onError: [{
937
+ guard: "isUserAlreadyConfirmed",
938
+ target: "#signUpActor.resolved"
939
+ }, { actions: "setRemoteError" }]
940
+ }
941
+ },
942
+ signUp: {
943
+ initial: "idle",
944
+ exit: "clearError",
945
+ on: { FEDERATED_SIGN_IN: { target: "#signUpActor.federatedSignIn" } },
946
+ states: {
947
+ idle: {
948
+ entry: "sendUpdate",
949
+ on: { SUBMIT: { target: "submit" } }
950
+ },
951
+ submit: {
952
+ tags: "pending",
953
+ entry: [
954
+ "sendUpdate",
955
+ "setUsername",
956
+ "clearError"
957
+ ],
958
+ invoke: {
959
+ src: "signUp",
960
+ input: ({ event }) => event.data,
961
+ onDone: [
962
+ {
963
+ guard: "hasCompletedSignUp",
964
+ actions: "setNextSignUpStep",
965
+ target: "#signUpActor.resolved"
966
+ },
967
+ {
968
+ guard: "shouldAutoSignIn",
969
+ actions: "setNextSignUpStep",
970
+ target: "#signUpActor.autoSignIn"
971
+ },
972
+ {
973
+ actions: ["setCodeDeliveryDetails", "setNextSignUpStep"],
974
+ target: "#signUpActor.init"
975
+ }
976
+ ],
977
+ onError: {
978
+ actions: "setRemoteError",
979
+ target: "idle"
980
+ }
981
+ }
982
+ }
983
+ }
984
+ },
985
+ confirmSignUp: {
986
+ initial: "idle",
987
+ exit: "clearError",
988
+ states: {
989
+ idle: {
990
+ entry: "sendUpdate",
991
+ on: {
992
+ SUBMIT: { target: "submit" },
993
+ RESEND: { target: "#signUpActor.resendSignUpCode" }
994
+ }
995
+ },
996
+ submit: {
997
+ tags: "pending",
998
+ entry: ["sendUpdate", "clearError"],
999
+ invoke: {
1000
+ src: "confirmSignUp",
1001
+ input: ({ context: { username }, event }) => ({
1002
+ username,
1003
+ ...event.data
1004
+ }),
1005
+ onDone: [
1006
+ {
1007
+ guard: "hasCompletedSignUp",
1008
+ actions: "setNextSignUpStep",
1009
+ target: "#signUpActor.resolved"
1010
+ },
1011
+ {
1012
+ guard: "shouldAutoSignIn",
1013
+ actions: "setNextSignUpStep",
1014
+ target: "#signUpActor.autoSignIn"
1015
+ },
1016
+ {
1017
+ actions: "setNextSignUpStep",
1018
+ target: "#signUpActor.init"
1019
+ }
1020
+ ],
1021
+ onError: {
1022
+ actions: "setRemoteError",
1023
+ target: "idle"
1024
+ }
1025
+ }
1026
+ }
1027
+ }
1028
+ },
1029
+ resolved: { type: "final" }
1030
+ },
1031
+ output: ({ context }) => context
1032
+ });
1033
+ };
1034
+
1035
+ //#endregion
1036
+ //#region src/machines/verifyUserAttributes/actor.ts
1037
+ /**
1038
+ * @internal
1039
+ */
1040
+ const verifyUserAttributesActor = (handlers, overridesContext) => {
1041
+ return setup({
1042
+ types: {
1043
+ context: {},
1044
+ events: {}
1045
+ },
1046
+ guards: {},
1047
+ actors: {
1048
+ sendUserAttributeVerificationCode: fromPromise(({ input }) => handlers.sendUserAttributeVerificationCode(input)),
1049
+ confirmVerifyUserAttribute: fromPromise(({ input }) => handlers.confirmUserAttribute(input))
1050
+ },
1051
+ actions: {
1052
+ sendUpdate: sendParent({ type: "CHILD_CHANGED" }),
1053
+ setCodeDeliveryDetails: assign({ codeDeliveryDetails: setCodeDeliveryDetails }),
1054
+ setSelectedUserAttribute: assign({ selectedUserAttribute: setSelectedUserAttribute }),
1055
+ setConfirmAttributeCompleteStep: assign({ step: setConfirmAttributeCompleteStep }),
1056
+ setRemoteError: assign({ remoteError: setRemoteError }),
1057
+ clearError: assign({ remoteError: void 0 }),
1058
+ clearSelectedUserAttribute: assign({ selectedUserAttribute: void 0 })
1059
+ }
1060
+ }).createMachine({
1061
+ id: "vefiryUserAttributesActor",
1062
+ initial: "selectUserAttributes",
1063
+ context: ({ input }) => ({
1064
+ step: "SIGN_IN",
1065
+ ...overridesContext,
1066
+ ...input
1067
+ }),
1068
+ states: {
1069
+ selectUserAttributes: {
1070
+ initial: "idle",
1071
+ exit: "clearError",
1072
+ states: {
1073
+ idle: {
1074
+ entry: "sendUpdate",
1075
+ on: {
1076
+ SKIP: { target: "#vefiryUserAttributesActor.resolved" },
1077
+ SUBMIT: { target: "submit" }
1078
+ }
1079
+ },
1080
+ submit: {
1081
+ tags: "pending",
1082
+ entry: ["sendUpdate", "clearError"],
1083
+ invoke: {
1084
+ src: "sendUserAttributeVerificationCode",
1085
+ input: ({ event }) => event.data,
1086
+ onDone: {
1087
+ actions: ["setSelectedUserAttribute", "setCodeDeliveryDetails"],
1088
+ target: "#vefiryUserAttributesActor.confirmVerifyUserAttribute"
1089
+ },
1090
+ onError: {
1091
+ actions: "setRemoteError",
1092
+ target: "idle"
1093
+ }
1094
+ }
1095
+ }
1096
+ }
1097
+ },
1098
+ confirmVerifyUserAttribute: {
1099
+ initial: "idle",
1100
+ exit: "clearError",
1101
+ states: {
1102
+ idle: {
1103
+ entry: "sendUpdate",
1104
+ on: {
1105
+ SUBMIT: { target: "submit" },
1106
+ RESEND: { target: "resendCode" },
1107
+ SKIP: { target: "#vefiryUserAttributesActor.resolved" }
1108
+ }
1109
+ },
1110
+ resendCode: {
1111
+ tags: "pending",
1112
+ entry: ["sendUpdate", "clearError"],
1113
+ invoke: {
1114
+ src: "sendUserAttributeVerificationCode",
1115
+ input: ({ context, event }) => ({
1116
+ userAttributeKey: context.selectedUserAttribute,
1117
+ ...event.data
1118
+ }),
1119
+ onDone: { target: "idle" },
1120
+ onError: {
1121
+ actions: "setRemoteError",
1122
+ target: "idle"
1123
+ }
1124
+ }
1125
+ },
1126
+ submit: {
1127
+ tags: "pending",
1128
+ entry: ["sendUpdate", "clearError"],
1129
+ invoke: {
1130
+ src: "confirmVerifyUserAttribute",
1131
+ input: ({ context, event }) => ({
1132
+ userAttributeKey: context.selectedUserAttribute,
1133
+ ...event.data
1134
+ }),
1135
+ onDone: {
1136
+ actions: ["setConfirmAttributeCompleteStep", "clearSelectedUserAttribute"],
1137
+ target: "#vefiryUserAttributesActor.resolved"
1138
+ },
1139
+ onError: {
1140
+ actions: "setRemoteError",
1141
+ target: "idle"
1142
+ }
1143
+ }
1144
+ }
1145
+ }
1146
+ },
1147
+ resolved: { type: "final" }
1148
+ },
1149
+ output: ({ context }) => context
1150
+ });
1151
+ };
1152
+
1153
+ //#endregion
1154
+ //#region src/machines/index.ts
1155
+ /**
1156
+ * @internal
1157
+ */
1158
+ const createAuthenticatorMachine = (options) => {
1159
+ const { handlers: customHandlers,...config } = options ?? {};
1160
+ const handlers = {
1161
+ ...defaultHandlers,
1162
+ ...customHandlers
1163
+ };
1164
+ return setup({
1165
+ types: {
1166
+ context: {},
1167
+ events: {}
1168
+ },
1169
+ guards: {
1170
+ hasCompletedAttributeConfirmation: ({ event: { output } }) => hasCompletedAttributeConfirmation(output?.step),
1171
+ hasUser: ({ context }) => !!context.user,
1172
+ isInitialStateSignUp: ({ context }) => context.config?.initialState === "signUp",
1173
+ isInitialStateResetPassword: ({ context }) => context.config?.initialState === "forgotPassword",
1174
+ isConfirmSignUpStep: ({ event: { output } }) => isConfirmSignUpStep(output?.step),
1175
+ isConfirmUserAttributeStep: ({ event: { output } }) => isConfirmUserAttributeStep(output?.step),
1176
+ isShouldConfirmUserAttributeStep: ({ event: { output } }) => isShouldConfirmUserAttributeStep(output?.step),
1177
+ isResetPasswordStep: ({ event: { output } }) => isResetPasswordStep(output?.step)
1178
+ },
1179
+ actors: {
1180
+ getCurrentUser: fromPromise(() => handlers.getCurrentUser()),
1181
+ invokeSignInActor: signInActor(handlers),
1182
+ invokeSignUpActor: signUpActor(handlers),
1183
+ invokeForgotPasswordActor: forgotPasswordActor(handlers),
1184
+ invokeVerifyUserAttributesActor: verifyUserAttributesActor(handlers),
1185
+ invokeSignOutActor: signOutActor(handlers)
1186
+ },
1187
+ actions: {
1188
+ clearActorDoneData: assign({ actorDoneData: void 0 }),
1189
+ clearUser: assign({ user: void 0 }),
1190
+ forwardToActor: forwardTo("childActor"),
1191
+ setUser: assign({ user: ({ event }) => event.output }),
1192
+ setActorDoneData: assign({ actorDoneData: ({ event }) => event.output })
1193
+ }
1194
+ }).createMachine({
1195
+ id: "authenticator",
1196
+ initial: "idle",
1197
+ context: {
1198
+ config,
1199
+ user: void 0
1200
+ },
1201
+ states: {
1202
+ idle: { invoke: {
1203
+ src: "getCurrentUser",
1204
+ onDone: {
1205
+ actions: "setUser",
1206
+ target: "#authenticator.setup"
1207
+ },
1208
+ onError: { target: "#authenticator.setup" }
1209
+ } },
1210
+ setup: {
1211
+ initial: "init",
1212
+ states: { init: { always: [
1213
+ {
1214
+ guard: "hasUser",
1215
+ target: "#authenticator.authenticated"
1216
+ },
1217
+ {
1218
+ guard: "isInitialStateSignUp",
1219
+ target: "#authenticator.signUpActor"
1220
+ },
1221
+ {
1222
+ guard: "isInitialStateResetPassword",
1223
+ target: "#authenticator.forgotPasswordActor"
1224
+ },
1225
+ { target: "#authenticator.signInActor" }
1226
+ ] } }
1227
+ },
1228
+ getCurrentUser: { invoke: {
1229
+ src: "getCurrentUser",
1230
+ onDone: {
1231
+ actions: "setUser",
1232
+ target: "#authenticator.authenticated"
1233
+ },
1234
+ onError: { target: "setup" }
1235
+ } },
1236
+ signInActor: {
1237
+ invoke: {
1238
+ id: "childActor",
1239
+ src: "invokeSignInActor",
1240
+ input: ({ context }) => context.actorDoneData,
1241
+ onDone: [
1242
+ {
1243
+ guard: "hasCompletedAttributeConfirmation",
1244
+ target: "#authenticator.getCurrentUser"
1245
+ },
1246
+ {
1247
+ guard: "isShouldConfirmUserAttributeStep",
1248
+ actions: "setActorDoneData",
1249
+ target: "#authenticator.verifyUserAttributesActor"
1250
+ },
1251
+ {
1252
+ guard: "isResetPasswordStep",
1253
+ actions: "setActorDoneData",
1254
+ target: "#authenticator.forgotPasswordActor"
1255
+ },
1256
+ {
1257
+ guard: "isConfirmSignUpStep",
1258
+ actions: "setActorDoneData",
1259
+ target: "#authenticator.signUpActor"
1260
+ }
1261
+ ]
1262
+ },
1263
+ entry: "clearActorDoneData",
1264
+ on: {
1265
+ FORGOT_PASSWORD: { target: "#authenticator.forgotPasswordActor" },
1266
+ SIGN_IN: { target: "#authenticator.signInActor" },
1267
+ SIGN_UP: { target: "#authenticator.signUpActor" },
1268
+ FEDERATED_SIGN_IN: { actions: "forwardToActor" },
1269
+ SUBMIT: { actions: "forwardToActor" }
1270
+ }
1271
+ },
1272
+ signUpActor: {
1273
+ invoke: {
1274
+ id: "childActor",
1275
+ src: "invokeSignUpActor",
1276
+ input: ({ context }) => context.actorDoneData,
1277
+ onDone: [
1278
+ {
1279
+ guard: "hasCompletedAttributeConfirmation",
1280
+ actions: "clearActorDoneData",
1281
+ target: "#authenticator.getCurrentUser"
1282
+ },
1283
+ {
1284
+ guard: "isShouldConfirmUserAttributeStep",
1285
+ actions: "setActorDoneData",
1286
+ target: "#authenticator.verifyUserAttributesActor"
1287
+ },
1288
+ {
1289
+ guard: "isConfirmUserAttributeStep",
1290
+ actions: "clearActorDoneData",
1291
+ target: "#authenticator.verifyUserAttributesActor"
1292
+ },
1293
+ {
1294
+ actions: "setActorDoneData",
1295
+ target: "#authenticator.signInActor"
1296
+ }
1297
+ ]
1298
+ },
1299
+ on: {
1300
+ SIGN_IN: { target: "#authenticator.signInActor" },
1301
+ FEDERATED_SIGN_IN: { actions: "forwardToActor" },
1302
+ RESEND: { actions: "forwardToActor" },
1303
+ SUBMIT: { actions: "forwardToActor" }
1304
+ }
1305
+ },
1306
+ forgotPasswordActor: {
1307
+ invoke: {
1308
+ id: "childActor",
1309
+ src: "invokeForgotPasswordActor",
1310
+ input: ({ context }) => context.actorDoneData,
1311
+ onDone: { target: "#authenticator.signInActor" }
1312
+ },
1313
+ exit: "clearActorDoneData",
1314
+ on: {
1315
+ SIGN_IN: { target: "#authenticator.signInActor" },
1316
+ RESEND: { actions: "forwardToActor" },
1317
+ SUBMIT: { actions: "forwardToActor" }
1318
+ }
1319
+ },
1320
+ verifyUserAttributesActor: {
1321
+ invoke: {
1322
+ id: "childActor",
1323
+ src: "invokeVerifyUserAttributesActor",
1324
+ input: ({ context }) => context.actorDoneData,
1325
+ onDone: {
1326
+ actions: "setActorDoneData",
1327
+ target: "#authenticator.getCurrentUser"
1328
+ }
1329
+ },
1330
+ on: {
1331
+ SKIP: { actions: "forwardToActor" },
1332
+ RESEND: { actions: "forwardToActor" },
1333
+ SUBMIT: { actions: "forwardToActor" }
1334
+ }
1335
+ },
1336
+ authenticated: {
1337
+ initial: "idle",
1338
+ on: { SIGN_OUT: "signOut" },
1339
+ states: {
1340
+ idle: { on: { TOKEN_REFRESH: "refreshUser" } },
1341
+ refreshUser: { invoke: {
1342
+ src: "getCurrentUser",
1343
+ onDone: {
1344
+ actions: "setUser",
1345
+ target: "idle"
1346
+ },
1347
+ onError: { target: "#authenticator.signOut" }
1348
+ } }
1349
+ }
1350
+ },
1351
+ signOut: {
1352
+ invoke: {
1353
+ id: "childActor",
1354
+ src: "invokeSignOutActor",
1355
+ onDone: {
1356
+ actions: "clearUser",
1357
+ target: "#authenticator.setup"
1358
+ }
1359
+ },
1360
+ exit: "clearActorDoneData"
1361
+ }
1362
+ },
1363
+ on: {
1364
+ CHILD_CHANGED: { actions: assign(({ context }) => context) },
1365
+ SIGN_IN_WITH_REDIRECT: { target: "#authenticator.getCurrentUser" }
1366
+ }
1367
+ });
1368
+ };
1369
+
1370
+ //#endregion
1371
+ export { createAuthenticatorMachine };
1372
+ //# sourceMappingURL=machines-CRIehDHl.js.map