Last active
June 23, 2021 14:55
-
-
Save abhayarawal/3146e7eb0c11d97fec34f8e93fe76c53 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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