Skip to content

Instantly share code, notes, and snippets.

@shmidt-i
Last active February 13, 2020 16:22
Show Gist options
  • Save shmidt-i/2c7cdd9cb6e9819edf34c8df39634bc0 to your computer and use it in GitHub Desktop.
Save shmidt-i/2c7cdd9cb6e9819edf34c8df39634bc0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "root",
context: {
authorizationCode: "123"
},
initial: "INIT",
states: {
"NOT AUTHORIZED": {
on: {
LOGIN: "AUTHORIZING"
}
},
FAILURE: {},
INIT: {
on: {
"*": [
{
target: "CALLBACK.MAYBE AUTHORIZED",
cond: "hasAuthorizationCode"
},
{ target: "NOT AUTHORIZED" }
]
}
},
AUTHORIZING: {
entry: "redirectToProvider"
},
CALLBACK: {
initial: "MAYBE AUTHORIZED",
states: {
"MAYBE AUTHORIZED": {
on: {
"*": [
{
target: "REQUESTING ACCESS TOKEN",
cond: "hasAuthorizationCode"
},
{ target: "#root.NOT AUTHORIZED" }
]
}
},
"REQUESTING ACCESS TOKEN": {
entry: "exchangeAuthCodeForAccessToken",
on: {
SUCC: "REQUESTING SESSION",
FAIL: "#root.FAILURE"
}
},
"REQUESTING SESSION": {
on: {
SUCC: "AUTHORIZED",
FAIL: "#root.FAILURE"
}
},
AUTHORIZED: {
// on:
}
}
}
}
},{
guards: {
"hasAuthorizationCode": ctx => typeof ctx.authorizationCode !== 'undefined'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment