Skip to content

Instantly share code, notes, and snippets.

@abhayarawal
Last active June 23, 2021 14:55
Show Gist options
  • Select an option

  • Save abhayarawal/3146e7eb0c11d97fec34f8e93fe76c53 to your computer and use it in GitHub Desktop.

Select an option

Save abhayarawal/3146e7eb0c11d97fec34f8e93fe76c53 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loginMachine = Machine({
id: 'login',
initial: 'start',
context: {
retries: 0,
loginDetails: null,
errorMessage: null
},
states: {
start: {
on: {
LOGIN_WITH_PASSWORD: 'withPassword',
CONFIRM_RESET: 'confirmReset'
}
},
withPassword: {
onDone: 'success',
on: {
RESET_PASSWORD: 'resetPassword',
LOGIN_PASSWORDLESS: 'passwordless'
},
initial: 'enteringEmail',
states: {
enteringEmail: {
on: {
ENTER_PASSWORD: {
target: 'enteringPassword',
actions: ['assignEmailToContext']
}
},
onEntry: ['clearErrorMessage']
},
enteringPassword: {
on: {
CONFIRM_WITH_PASSWORD: {
target: 'confirming',
actions: ['assignPasswordToContext']
},
BACK: 'enteringEmail'
},
onExit: ['clearErrorMessage']
},
confirming: {
invoke: {
src: 'loginWithPassword',
onDone: {
target: 'complete'
},
onError: {
target: 'enteringPassword',
actions: ['assignErrorMessageToContext']
}
}
},
complete: {
type: 'final'
}
}
},
passwordless: {},
resetPassword: {
onDone: 'withPassword',
on: {
BACK: 'withPassword'
},
initial: 'enteringEmail',
states: {
enteringEmail: {
on: {
CONFIRM_PASSWORD_RESET: {
target: 'confirming',
actions: ['assignDetailsToContext']
}
},
onExit: ['clearErrorMessage']
},
confirming: {
invoke: {
src: 'resetPassword',
onDone: {
target: 'complete'
},
onError: {
target: 'enteringEmail',
actions: ['assignErrorMessageToContext']
}
}
},
complete: {
type: 'final'
}
}
},
confirmReset: {
onDone: 'withPassword'
},
success: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment