Last active
December 20, 2020 08:09
-
-
Save massimoselvi/df5ae16471d6fc3c5ddacf74a19d22c3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
/* | |
* AUTH FLOW example | |
* https://xstate.js.org/viz/?gist=df5ae16471d6fc3c5ddacf74a19d22c3 | |
*/ | |
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'fetch', | |
initial: 'signingWithEmailOrPhone', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
signingWithEmailOrPhone: { | |
on: { | |
SUBMIT_SIGNIN: 'signingIn' | |
} | |
}, | |
signingIn: { | |
on: { | |
RESOLVE: 'insertAccessCode', | |
REJECT: 'signUpWithUserData' | |
} | |
}, | |
signUpWithUserData: { | |
// firstname, lastname, policies,... | |
on: { | |
SUBMIT_SIGNUP: 'signingUpToCognito' | |
} | |
}, | |
signingUpToCognito: { | |
on: { | |
RESOLVE: 'insertAccessCode', | |
REJECT: 'failure' | |
} | |
}, | |
insertAccessCode: { | |
on: { | |
SUBMIT_CODE: 'verifyingCode' | |
} | |
}, | |
verifyingCode: { | |
on: { | |
RESOLVE: 'checkingProfile', | |
REJECT: 'failure' | |
} | |
}, | |
checkingProfile: { | |
on: { | |
RESOLVE: 'success', | |
REJECT: 'createProfile' | |
} | |
}, | |
createProfile: { | |
// REUSE firstname, lastname, policies,... FROM BEFORE (client app) | |
on: { | |
SUBMIT_USER_PROFILE: 'creatingProfile' | |
} | |
}, | |
creatingProfile: { | |
on: { | |
RESOLVE: 'success', | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'signingWithEmailOrPhone', | |
actions: assign({ | |
retries: (context, event) => context.retries + 1 | |
}) | |
} | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment