Skip to content

Instantly share code, notes, and snippets.

@ahrjarrett
Last active September 17, 2020 15:25
Show Gist options
  • Select an option

  • Save ahrjarrett/a38c68f9c89d5618051b0cfc617b8be1 to your computer and use it in GitHub Desktop.

Select an option

Save ahrjarrett/a38c68f9c89d5618051b0cfc617b8be1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'GDAuth',
initial: 'idle',
context: {
user: null
},
states: {
idle: {
on: {
TEST_EXECUTION_ENV: 'ssr'
}
},
ssr: {
on: {
INITIALIZE: 'init'
}
},
init: {
on: {
READ_CONTEXT: 'authFromContext'
}
},
authFromContext: {
on: {
READ_CACHE: 'authFromCache'
}
},
authFromCache: {
on: {
TRY_SSO: 'ssoPending'
}
},
ssoPending: {
invoke: {
id: 'resolveSSO',
src: async (context, event) => {
const result = await event(context)
return result
},
onDone: {
target: 'success',
actions: assign({ loggedIn: (_, event) => event.data
}),
},
onError: {
target: 'ssoFailure',
},
}
},
ssoFailure: {
on: {
TRY_SDK: 'sdkPending'
}
},
sdkPending: {
invoke: {
id: 'resolveSdk',
src: async (context, event) => {
const result = await event(context)
return result
},
onDone: {
target: 'success',
actions: assign({ loggedIn: (_, event) => event.data
}),
},
onError: {
target: 'failure'
}
}
},
failure: {
type: 'final'
},
success: {
type: 'final'
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment