Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created August 18, 2021 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmbtech/392ebae19ff03fb0511a69822b99be51 to your computer and use it in GitHub Desktop.
Save tmbtech/392ebae19ff03fb0511a69822b99be51 to your computer and use it in GitHub Desktop.
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: 'auth',
initial: 'checkOktaLoggedIn',
context: {},
states: {
checkOktaLoggedIn: {
invoke: {
id: 'verifyOktaLoggedIn',
src: 'verifyOktaLoggedIn',
onDone: {
target: 'isLoggedIn',
},
onError: 'isNotLoggedIn',
},
},
isLoggedIn: {
exit: ['cleanupLocalStorage'],
on: {
LOGOUT: 'loggingOut',
LOGOUT_NO_REDIRECT: 'loggingOutNoRedirect',
LOGOUT_CUSTOM_REDIRECT: {
target: 'loggingOutCustomRedirect',
actions: ['setRedirectURI'],
},
},
},
isNotLoggedIn: {
exit: ['cleanupLocalStorage'],
on: {
LOGIN_OKTA: {
target: 'clearCacheBeforeLoggedIn',
actions: ['storeOktaToken'],
},
},
},
clearCacheBeforeLoggedIn: {
invoke: {
id: 'clearCache',
src: 'clearCache',
onDone: {
target: 'isLoggedIn',
},
onError: {
target: 'isLoggedIn',
},
},
},
loggingOut: {
invoke: {
id: 'logout',
src: 'logout',
onDone: {
target: 'isNotLoggedIn',
actions: ['clearSegment', 'redirectToLogin'],
},
onError: {
target: 'isNotLoggedIn',
actions: ['clearSegment', 'redirectToLogin'],
},
},
},
loggingOutNoRedirect: {
invoke: {
id: 'logout-no-redirect',
src: 'logout',
onDone: {
target: 'isNotLoggedIn',
actions: ['clearSegment'],
},
onError: {
target: 'isNotLoggedIn',
actions: ['clearSegment'],
},
},
},
loggingOutCustomRedirect: {
invoke: {
id: 'logout-custom-redirect',
src: 'logout',
onDone: {
target: 'isNotLoggedIn',
actions: ['redirectCustomLocation', 'clearSegment'],
},
onError: {
target: 'isNotLoggedIn',
actions: ['redirectCustomLocation', 'clearSegment'],
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment