Skip to content

Instantly share code, notes, and snippets.

@kepi74
Created July 31, 2023 05:44
Show Gist options
  • Save kepi74/42b731447bbd139413604c3b018492fa to your computer and use it in GitHub Desktop.
Save kepi74/42b731447bbd139413604c3b018492fa 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: 'signIn',
initial: 'idle',
context: {
error: null,
signInWaitTiemout: 0,
role: 'Seller',
password: '',
username: '',
targetURL: null,
token: null,
},
states: {
idle: {
on: {
SUBMIT: {
target: 'submitting',
actions: ['clearError', 'setCredentials'],
},
},
},
submitting: {
invoke: {
src: 'authenticate',
id: 'authenticate',
onDone: [
{
cond: 'isAuthenticated',
actions: ['setToken', 'setTargetURL'],
target: 'success',
},
{
cond: 'tooManyLoginAttempts',
actions: ['setAuthenticationError', 'setSignInWaitTimeout'],
target: 'signInBlocked',
},
{
actions: 'setAuthenticationError',
target: 'idle',
},
],
},
},
signInBlocked: {
invoke: {
id: 'signInBlockedCountdown',
src: 'signInBlockedCountdown',
},
on: {
TICK: [
{
cond: 'isSignInWaitTimeoutExpired',
actions: 'clearSignInWaitTimeout',
target: 'idle',
},
{
actions: 'decrementSignInWaitTimeout',
},
],
},
},
success: {
type: 'final',
invoke: [
{
id: 'persistToken',
src: 'persistToken',
},
{
id: 'redirectToTargetRoleURL',
src: 'redirectToTargetRoleURL',
},
],
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment