Last active
May 26, 2020 23:58
-
-
Save jimmynotjim/2b0d1da8bb928359c77ab1b4ae58cf6b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const challengeEmailState = { | |
initial: "confirmEmailVerification", | |
context: { | |
retries: 0 | |
}, | |
states: { | |
confirmEmailVerification: { | |
on: { | |
SUBMIT: "requestEmailChallenge" | |
} | |
}, | |
requestEmailChallenge: { | |
on: { | |
RESOLVE: "enterEmailChallenge", | |
REJECT: "confirmEmailVerification" | |
} | |
}, | |
enterEmailChallenge: { | |
on: { | |
SUBMIT: "verifyEmailChallenge" | |
} | |
}, | |
verifyEmailChallenge: { | |
on: { | |
RESOLVE: "verifyEmailSuccess", | |
REJECT: "verifyEmailFailure" | |
} | |
}, | |
verifyEmailSuccess: { | |
type: "final" | |
}, | |
verifyEmailFailure: { | |
on: { | |
RETRY: { | |
target: "enterEmailChallenge", | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
} | |
} | |
} | |
const challengePhoneState = { | |
initial: "confirmPhoneVerification", | |
context: { | |
retries: 0 | |
}, | |
states: { | |
confirmPhoneVerification: { | |
on: { | |
SUBMIT: "requestPhoneChallenge" | |
} | |
}, | |
requestPhoneChallenge: { | |
on: { | |
RESOLVE: "enterPhoneChallenge", | |
REJECT: "confirmPhoneVerification" | |
} | |
}, | |
enterPhoneChallenge: { | |
on: { | |
SUBMIT: "verifyPhoneChallenge", | |
CHANGE_NUMBER: "resetPhoneNumber" | |
} | |
}, | |
verifyPhoneChallenge: { | |
on: { | |
RESOLVE: "verifyPhoneSuccess", | |
REJECT: "verifyPhoneFailure" | |
} | |
}, | |
verifyPhoneSuccess: { | |
type: "final" | |
}, | |
verifyPhoneFailure: { | |
on: { | |
RETRY: { | |
target: "enterPhoneChallenge", | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
}, | |
resetPhoneNumber: { | |
type: "final" | |
} | |
} | |
} | |
const mfaMachine = Machine({ | |
id: "MFA_VERIFY", | |
initial: "unverified", | |
context: { | |
retries: 0 | |
}, | |
states: { | |
unverified: { | |
on: { | |
BEGIN: "challengeMethod" | |
} | |
}, | |
challengeMethod: { | |
on:{ | |
EMAIL: "challengeEmail", | |
PHONE: "challengePhone", | |
} | |
}, | |
challengeEmail: { | |
on: { | |
CONTINUE: "verified", | |
}, | |
...challengeEmailState | |
}, | |
challengePhone: { | |
on: { | |
CONTINUE: "verified", | |
RESET: "challengeEmail" | |
}, | |
...challengePhoneState | |
}, | |
verified: { | |
type: "final" | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment