Skip to content

Instantly share code, notes, and snippets.

@jimmynotjim
Created January 30, 2023 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmynotjim/7196cd6675235c9b4c396e11b628a7b1 to your computer and use it in GitHub Desktop.
Save jimmynotjim/7196cd6675235c9b4c396e11b628a7b1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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