Skip to content

Instantly share code, notes, and snippets.

@charlie632
Last active November 23, 2020 21:38
Show Gist options
  • Save charlie632/fd9a65aebdbba278c0c03a3623ac6c9d to your computer and use it in GitHub Desktop.
Save charlie632/fd9a65aebdbba278c0c03a3623ac6c9d 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: 'fetch',
initial: 'idle',
context: {
retries: 0
},
states: {
idle: {
on: {
START: 'fetchProviderSettings'
}
},
fetchProviderSettings: {
on: {
SUCCESS: 'switchCredentials'
}
},
switchCredentials: {
on: {
SUCCESS: 'verifyActiveSessionFromCookie',
FAILURE: 'goToLoginUrl'
}
},
verifyActiveSessionFromCookie: {
on: {
SUCCESS: 'end',
ERROR: 'goToLoginUrl'
}
},
goToLoginUrl: {
on: {
SUCCESS: 'fetchAccountData'
}
},
fetchAccountData: {
on: {
SUCCESS: 'injectCredentials'
}
},
injectCredentials: {
on: {
SUCCESS_WITH_MFA: 'checkMFAPrompted',
SUCCESS_NO_MFA: 'verifySuccessfulLogin'
}
},
checkMFAPrompted: {
on: {
PROMPTED_AUTO: 'waitForApproval',
PROPMTED: 'showTotpInstructions',
NOT_PROMPTED: 'verifySuccessfulLogin'
}
},
showTotpInstructions: {
on: {
DISMISS: 'end',
TIMEOUT: 'end'
}
},
waitForApproval: {
on: {
APPROVED: 'fetchTotp',
REJECTED: 'rejected'
}
},
fetchTotp: {
on: {
SUCCESS: 'injectTotp',
ERROR: 'error'
}
},
injectTotp: {
on: {
SUCCESS: 'verifySuccessfulLogin',
ERROR: 'error'
}
},
verifySuccessfulLogin: {
SUCCESS: 'end',
ERROR: 'error'
},
end: {
type: 'final'
},
error: {
type: 'final'
},
rejected: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment