Skip to content

Instantly share code, notes, and snippets.

@wmcbain
Last active March 5, 2020 19:43
Show Gist options
  • Save wmcbain/9b9a50749baeeb3f6b0697c0f6709bf2 to your computer and use it in GitHub Desktop.
Save wmcbain/9b9a50749baeeb3f6b0697c0f6709bf2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const authMachine = Machine({
id: 'auth_machine',
initial: 'authIsLoading',
context: {
sessionToken: null,
},
states: {
// HomeScreen.tsx
authIsLoading: {
on: {
LOGGED_IN: 'isLoggedIn',
NOT_LOGGED_IN: 'isNotLoggedIn',
},
},
// HomeScreen.tsx
isLoggedIn: {
entry: 'redirectToAccount',
type: 'final',
},
isNotLoggedIn: {
initial: 'waitForUserChoice',
onDone: 'waitForDeeplink',
states: {
// HomeScreen.tsx
waitForUserChoice: {
on: {
REGISTER: 'forkInRoad',
DEEPLINK_CAPTURED: 'phoneDeeplinkOverride',
},
},
// ForkInRoadScreen.tsx
forkInRoad: {
entry: 'redirectToForkInRoad',
on: {
REGISTER_PHONE_NUMBER: 'registerPhoneNumber',
CANCEL: 'waitForUserChoice',
},
},
// RegisterPhoneScreen.tsx
registerPhoneNumber: {
entry: 'redirectToRegisterPhoneNumber',
on: {
PHONE_NUMBER_SUBMITTED: 'submitPhoneNumber',
CANCEL: 'waitForUserChoice',
},
},
phoneDeeplinkOverride: {
type: 'final',
},
// HomeScreen.tsx
submitPhoneNumber: {
entry: 'phoneNumberSubmitted',
type: 'final',
},
},
},
// HomeScreen.tsx
waitForDeeplink: {
on: {
DEEPLINK_CAPTURED: 'verifySMSCode',
},
},
// HomeScreen.tsx
verifySMSCode: {
entry: 'verifySMSCode',
on: {
REGISTER_USER: 'registerUser',
},
},
// RegisterUserScreen.tsx
registerUser: {
entry: 'setSessionToken',
on: {
USER_REGISTERED: 'registrationComplete',
},
},
registrationComplete: {
entry: 'authenticateUser',
on: {
USER_AUTHENTICATED: 'isLoggedIn',
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment