Last active
May 8, 2020 07:49
-
-
Save robinandeer/ffe30f1deecd984897b0df3190ded42d 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const publicMachine = Machine({ | |
id: 'public', | |
initial: 'configLoading', | |
context: {}, | |
states: { | |
configLoading: { | |
invoke: { | |
id: 'loadConfig', | |
src: 'loadConfig', | |
onDone: { | |
target: 'configValidating', | |
actions: [ | |
assign({ config: (_, event) => event.data }), | |
'updateTranslations', | |
], | |
}, | |
onError: { | |
target: 'configFailure', | |
}, | |
}, | |
}, | |
configFailure: { | |
type: 'final', | |
}, | |
configValidating: { | |
entry: 'validateConfig', | |
on: { | |
FAIL_CONFIG_VALIDATION: 'configValidationFailure', | |
LOAD_AUTH: 'authLoading', | |
}, | |
}, | |
configValidationFailure: { | |
type: 'final', | |
}, | |
authLoading: { | |
invoke: { | |
id: 'loadAuth', | |
src: 'loadAuth', | |
onDone: { | |
target: 'userValidating', | |
actions: assign({ tokens: (_, event) => event.data }), | |
}, | |
onError: { | |
target: 'biometricsLoading', | |
actions: 'removeAuth', | |
}, | |
}, | |
}, | |
biometricsLoading: { | |
entry: 'loadBiometricAuth', | |
on: { | |
LOGIN_WITH_BIOMETRICS: 'biometricsAuthenticating', | |
SKIP_BIOMETRICS: 'loggedOut', | |
}, | |
}, | |
biometricsAuthenticating: { | |
invoke: { | |
id: 'biometricAuth', | |
src: 'biometricAuth', | |
onDone: { | |
target: 'userValidating', | |
actions: assign({ tokens: (_, event) => event.data }), | |
}, | |
onError: { | |
target: 'biometricsFailure', | |
}, | |
}, | |
}, | |
biometricsFailure: { | |
on: { | |
LOGIN_WITH_BIOMETRICS: 'biometricsAuthenticating', | |
TEAR_DOWN_BIOMETRICS: { | |
target: 'loggedOut', | |
actions: 'tareDownBiometrics', | |
}, | |
}, | |
}, | |
loggedOut: { | |
on: { | |
LOGIN: 'authenticating', | |
}, | |
}, | |
authenticating: { | |
invoke: { | |
id: 'authenticate', | |
src: 'authenticate', | |
onDone: { | |
target: 'userValidating', | |
actions: assign({ tokens: (_, event) => event.data }), | |
}, | |
onError: { | |
target: 'loggedOut', | |
}, | |
}, | |
}, | |
userValidating: { | |
invoke: { | |
id: 'validateUser', | |
src: 'validateUser', | |
onDone: { | |
target: 'loggedIn', | |
actions: [assign({ cards: (_, event) => event.data }), 'saveAuth'], | |
}, | |
onError: { | |
target: 'userValidationFailure', | |
}, | |
}, | |
}, | |
userValidationFailure: { | |
on: { | |
DISMISS_AUTH_ERROR: 'loggedOut', | |
}, | |
}, | |
loggedIn: { | |
on: { | |
LOGOUT: { | |
target: 'loggedOut', | |
actions: [ | |
'removeAuth', | |
], | |
}, | |
}, | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment