Skip to content

Instantly share code, notes, and snippets.

@ilumin
Created November 10, 2020 10:26
Show Gist options
  • Save ilumin/b137cd23685daccce771d06183d43588 to your computer and use it in GitHub Desktop.
Save ilumin/b137cd23685daccce771d06183d43588 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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