Skip to content

Instantly share code, notes, and snippets.

@NoriSte
Last active August 1, 2019 10:27
Show Gist options
  • Save NoriSte/e1f435a944151a76cc1d70401243331d to your computer and use it in GitHub Desktop.
Save NoriSte/e1f435a944151a76cc1d70401243331d to your computer and use it in GitHub Desktop.
New Conio BO Auth Flow - Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'fetch',
initial: 'localTokens',
context: {
session401: 0
},
states: {
localTokens: {
on: {
"EXIST": 'sessionCheck',
"NOT.EXIST": 'loginForm'
}
},
loginForm: {
on: {
"200": "sessionCheck",
"401": "loginForm",
"500": "serverError",
}
},
sessionCheck: {
on: {
"200": 'sessionSuccess',
"401": {
target: 'session401Check',
// add retries check
actions: assign({
session401: (context, event) => context.session401 + 1
})
},
"500": "serverError"
}
},
sessionSuccess: {
type: 'final'
},
serverError: {
type: 'final'
},
session401Check: {
on: {
'': [
{ target: 'refreshToken', cond: 'firstTry' },
{ target: 'serverError', cond: 'secondTry' }
],
}
},
refreshToken: {
on: {
SUCCESS: "sessionCheck",
FAILURE: "loginForm"
}
}
}
}, {
guards: {
firstTry: context => context.session401 <= 1,
secondTry: context => context.session401 > 1,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment