Skip to content

Instantly share code, notes, and snippets.

@barucAlmaguer
Created December 1, 2020 21:57
Show Gist options
  • Save barucAlmaguer/bb5f0f7252ec4334497205bf2a2462ae to your computer and use it in GitHub Desktop.
Save barucAlmaguer/bb5f0f7252ec4334497205bf2a2462ae to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loginMachine = Machine(
{
initial: 'howToLogin',
context: {
ssoUrl: undefined,
email: '',
password: '',
error: undefined,
client: undefined,
},
states: {
validateSso: {
on: {
"": [{
target: 'howToLogin'
}
]
}
},
howToLogin: {
on: {
WITH_SSO: {
target: 'loadingSso',
actions: ['setSessionSsoInfo'],
},
WITH_EMAIL_PASS: 'loggedOut'
}
},
loggedOut: {
on: {
CLICK_LOGIN: {
target: 'loading',
},
CHANGE_EMAIL: {
actions: 'setEmail',
},
CHANGE_PASSWORD: {
actions: 'setPassword',
},
},
},
loadingSso: {
type: 'final',
onEntry: 'redirectHome',
},
loading: {
invoke: {
src: 'tryLogin',
onDone: [
{
target: 'loggedIn',
cond: 'isLoginSuccessful',
actions: ['setSessionInfo'],
},
{ target: 'errorOnLogin', actions: ['setErrors'] },
],
onError: {
target: 'errorOnLogin',
actions: ['setErrors'],
},
},
},
errorOnLogin: {
on: {
CLICK_LOGIN: {
target: 'loading',
},
CHANGE_EMAIL: {
actions: 'setEmail',
},
CHANGE_PASSWORD: {
actions: 'setPassword',
},
},
},
loggedIn: {
type: 'final',
onEntry: 'redirectHome',
},
},
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment