Skip to content

Instantly share code, notes, and snippets.

@austinsamsel
Last active April 23, 2021 20:53
Show Gist options
  • Save austinsamsel/dbda18d8b3aac26db71c8d5e8c89a651 to your computer and use it in GitHub Desktop.
Save austinsamsel/dbda18d8b3aac26db71c8d5e8c89a651 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - actions
// - XState (all XState exports)
const sessionDefinition = {
initial: 'LOADING',
context: {
currentUser: null,
},
states: {
LOADING: {
on: {
CURRENT_USER: {
target: 'AUTHED_NO_WALLET',
actions: 'sendTokenToAPI', // @TODO
},
NO_CURRENT_USER: {
target: 'NO_AUTH',
},
},
},
NO_AUTH: {
on: {
SIGN_IN: {
target: 'REDIRECT',
actions: ['signIn'], // @TODO move to authenticating onEntry:
},
},
},
AUTHED_NO_WALLET: {
on: {
SIGN_IN_WALLET: {
target: 'AUTHENTICATING_WALLET',
},
CLEAR_SESSION: {
target: 'REDIRECT',
actions: ['clearSession'],
},
},
},
AUTHENTICATING_WALLET: {
on: {
SIGNED: {
target: 'AUTHED_WALLET',
actions: ['subscribeToFlow'],
},
SIGN_FAIL: {
target: 'AUTHED_NO_WALLET',
},
},
},
AUTHED_WALLET: {
on: {
CLEAR_SESSION: {
target: 'REDIRECT',
actions: ['clearSession'],
},
},
},
REDIRECT: {}, // redirect happens here
},
};
const sessionMachine = Machine(sessionDefinition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment