|
1 | 1 | import { assign, createMachine, forwardTo, spawn } from 'xstate'; |
| 2 | +import { choose } from 'xstate/lib/actions'; |
2 | 3 |
|
3 | 4 | import { |
4 | 5 | AuthContext, |
@@ -205,14 +206,18 @@ export function createAuthenticatorMachine() { |
205 | 206 | SUBMIT: { actions: 'forwardToActor' }, |
206 | 207 | FEDERATED_SIGN_IN: { actions: 'forwardToActor' }, |
207 | 208 | RESEND: { actions: 'forwardToActor' }, |
208 | | - SIGN_OUT: { actions: 'forwardToActor' }, |
209 | 209 | SIGN_IN: { actions: 'forwardToActor' }, |
210 | 210 | SKIP: { actions: 'forwardToActor' }, |
211 | 211 | }, |
212 | 212 | }, |
213 | 213 | { |
214 | 214 | actions: { |
215 | | - forwardToActor: forwardTo((context) => context.actorRef), |
| 215 | + forwardToActor: choose([ |
| 216 | + { |
| 217 | + cond: 'hasActor', |
| 218 | + actions: forwardTo((context) => context.actorRef), |
| 219 | + }, |
| 220 | + ]), |
216 | 221 | setUser: assign({ |
217 | 222 | user: (_, event) => event.data as CognitoUserAmplify, |
218 | 223 | }), |
@@ -369,6 +374,8 @@ export function createAuthenticatorMachine() { |
369 | 374 | shouldRedirectToResetPassword: (_, event) => |
370 | 375 | event.data?.intent === 'confirmPasswordReset', |
371 | 376 | shouldSetup: (context) => context.hasSetup === false, |
| 377 | + // other context guards |
| 378 | + hasActor: (context) => !!context.actorRef, |
372 | 379 | }, |
373 | 380 | services: { |
374 | 381 | getCurrentUser: (context, _) => context.services.getCurrentUser(), |
|
0 commit comments