Last active
February 13, 2020 16:22
-
-
Save shmidt-i/2c7cdd9cb6e9819edf34c8df39634bc0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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