Skip to content

Commit 8f81479

Browse files
authored
fix(authenticator): fix infinite loop on refresh after refresh token expires (#1863)
* Add hasActor condition to forwardTo * Remove unneeded signout event
1 parent 04c49c4 commit 8f81479

File tree

1 file changed

+9
-2
lines changed
  • packages/ui/src/machines/authenticator

1 file changed

+9
-2
lines changed

packages/ui/src/machines/authenticator/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assign, createMachine, forwardTo, spawn } from 'xstate';
2+
import { choose } from 'xstate/lib/actions';
23

34
import {
45
AuthContext,
@@ -205,14 +206,18 @@ export function createAuthenticatorMachine() {
205206
SUBMIT: { actions: 'forwardToActor' },
206207
FEDERATED_SIGN_IN: { actions: 'forwardToActor' },
207208
RESEND: { actions: 'forwardToActor' },
208-
SIGN_OUT: { actions: 'forwardToActor' },
209209
SIGN_IN: { actions: 'forwardToActor' },
210210
SKIP: { actions: 'forwardToActor' },
211211
},
212212
},
213213
{
214214
actions: {
215-
forwardToActor: forwardTo((context) => context.actorRef),
215+
forwardToActor: choose([
216+
{
217+
cond: 'hasActor',
218+
actions: forwardTo((context) => context.actorRef),
219+
},
220+
]),
216221
setUser: assign({
217222
user: (_, event) => event.data as CognitoUserAmplify,
218223
}),
@@ -369,6 +374,8 @@ export function createAuthenticatorMachine() {
369374
shouldRedirectToResetPassword: (_, event) =>
370375
event.data?.intent === 'confirmPasswordReset',
371376
shouldSetup: (context) => context.hasSetup === false,
377+
// other context guards
378+
hasActor: (context) => !!context.actorRef,
372379
},
373380
services: {
374381
getCurrentUser: (context, _) => context.services.getCurrentUser(),

0 commit comments

Comments
 (0)