Last active
June 13, 2020 02:24
-
-
Save danielsdesk/200d5b466c47a845d8967cd9fa36529a 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const authMachine = Machine( | |
{ | |
id: "authentication", | |
initial: "unauthorized", | |
context: { | |
user: undefined, | |
message: undefined, | |
}, | |
states: { | |
unauthorized: { | |
entry: "resetUser", | |
on: { | |
LOGIN: "loading", | |
SIGNUP: "signup", | |
}, | |
}, | |
signup: { | |
invoke: { | |
src: "performSignup", | |
onDone: { target: "unauthorized", actions: "onSuccess" }, | |
onError: { target: "unauthorized", actions: "onError" }, | |
}, | |
}, | |
loading: { | |
invoke: { | |
src: "performLogin", | |
onDone: { target: "authorized", actions: "onSuccess" }, | |
onError: { target: "unauthorized", actions: "onError" }, | |
}, | |
}, | |
updating: { | |
invoke: { | |
src: "updateProfile", | |
onDone: { target: "refreshing" }, | |
onError: { target: "unauthorized", actions: "onError" }, | |
}, | |
}, | |
refreshing: { | |
invoke: { | |
src: "getUserProfile", | |
onDone: { target: "authorized", actions: "setUserProfile" }, | |
onError: { target: "unauthorized", actions: "onError" }, | |
}, | |
on: { | |
LOGOUT: "logout", | |
}, | |
}, | |
logout: { | |
invoke: { | |
src: "performLogout", | |
onDone: { target: "unauthorized" }, | |
onError: { target: "unauthorized", actions: "onError" }, | |
}, | |
}, | |
authorized: { | |
entry: "redirectHomeAfterLogin", | |
on: { | |
UPDATE: "updating", | |
REFRESH: "refreshing", | |
LOGOUT: "logout", | |
}, | |
}, | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment