Created
February 12, 2020 21:18
-
-
Save brookslybrand/b6580bb9f00a5f38c5fd8f19e9dc8daf 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
// this machine expects an authenticate service to be passed in | |
// and handles where a user is in the authentication process. | |
// `logedIn` is marked as final state because once logged in | |
// the auth-context will be updated by firebase and so the user | |
// will automatically be navigated away from this component | |
const authenticationMachine = Machine( | |
{ | |
id: 'authentication', | |
initial: 'loggedOut', | |
context: { | |
errorMessage: '' | |
}, | |
states: { | |
loggedOut: { | |
on: { | |
LOGIN: 'authenticating' | |
}, | |
initial: 'unchecked', | |
states: { | |
unchecked: {}, | |
error: {} | |
} | |
}, | |
authenticating: { | |
entry: 'resetError', | |
invoke: { | |
src: 'authenticate', | |
onDone: { | |
target: 'loggedIn', | |
internal: false | |
}, | |
onError: { | |
target: 'loggedOut.error', | |
internal: false, | |
actions: 'setError' | |
} | |
} | |
}, | |
loggedIn: { | |
type: 'final' | |
} | |
} | |
}, | |
{ | |
actions: { | |
setError: assign({ | |
errorMessage: (context, event) => event.data | |
}), | |
resetError: assign({ errorMessage: '' }) | |
}, | |
services: { | |
authenticate: () => | |
Promise.reject('authenticate must be passed in as an option') | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment