Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created January 30, 2020 01:08
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 tmbtech/e12bbc738a0ba16000564f9cca7ace90 to your computer and use it in GitHub Desktop.
Save tmbtech/e12bbc738a0ba16000564f9cca7ace90 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 fetchMachine = Machine({
id: "register_user",
initial: "checkUserStatus",
context: {
alleToken: null,
sessionToken: null,
oktaTokens: null,
registrationFields: {
firstName: "",
lastName: "",
emailAddress: "",
password: ""
}
},
states: {
checkUserStatus: {
initial: "checkUserLoggedIn",
states: {
checkUserLoggedIn: {
invoke: {
id: "checkIsLoggedIn",
src: "checkIsLoggedIn",
onDone: "isLoggedIn",
onError: "isNotLoggedIn"
}
},
isLoggedIn: {
entry: "redirectToAccount"
},
isNotLoggedIn: {
invoke: {
id: "verifySMSCode",
src: "verifySMSCode",
onDone: {
target: "#waitForInput",
actions: "setAlleToken"
},
onError: {
target: "#redirectToPhoneVerification",
actions: "redirectToPhoneVerification"
}
}
}
}
},
redirectToPhoneVerification: {
id: "redirectToPhoneVerification",
type: "final"
},
waitForInput: {
id: "waitForInput",
on: {
REGISTRATION_SUBMITTED: {
target: "hipaRequirement",
actions: "setRegistrationFields"
}
}
},
hipaRequirement: {
initial: "showHipaaNotice",
states: {
showHipaaNotice: {
on: {
DECLINE: "confirmHipaaDecline",
REGISTRATION_COMPLETE: {
target: "#getOktaToken",
actions: "setSessionToken"
},
REGISTRATION_ERROR: {
target: "acceptedHipaaWaitForInput"
}
}
},
acceptedHipaaWaitForInput: {
on: {
REGISTRATION_COMPLETE: {
target: "#getOktaToken",
actions: "setSessionToken"
},
REGISTRATION_ERROR: {
target: "acceptedHipaaWaitForInput"
}
}
},
confirmHipaaDecline: {
on: {
CLOSE: "showHipaaNotice",
EXIT_REGISTRATION: "#redirectToHomepage",
REGISTRATION_COMPLETE: {
target: "#getOktaToken",
actions: "setSessionToken"
},
REGISTRATION_ERROR: {
target: "acceptedHipaaWaitForInput"
}
}
}
}
},
oktaAuth: {
states: {
getOktaToken: {
id: "getOktaToken",
invoke: {
id: "getOktaToken",
src: "getOktaToken",
onDone: {
target: "updateTokenManager",
actions: "setOktaTokens"
},
onError: "#redirectToLogin"
}
},
updateTokenManager: {
invoke: {
id: "updateTokenManger",
src: "updateTokenManager",
onDone: "#registrationComplete",
onError: "#redirectToLogin"
}
}
}
},
redirects: {
states: {
redirectToLogin: {
id: "redirectToLogin",
entry: "redirectToLogin",
type: "final"
},
registrationComplete: {
id: "registrationComplete",
entry: "redirectToAccount",
type: "final"
},
redirectToHomepage: {
id: "redirectToHomepage",
entry: "redirectToHomepage",
type: "final"
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment