Last active
December 29, 2019 07:54
-
-
Save damooo/d14401e51f0ee59934b65bd6a32d69b1 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 AuthFSM = Machine({ | |
id: 'AuthMachine', | |
initial: 'init', | |
context: {}, | |
states: { | |
init: { | |
on: { | |
INIT_AUTH: 'authorized', | |
INIT_UNAUTH: 'unauthorized', | |
}, | |
}, | |
unauthorized: { | |
on: { | |
CMD_AUTH: { | |
target: 'authorizing', | |
actions: ['initAuthFlow'], | |
}, | |
SYNC_AUTH: { | |
target: 'authorized', | |
}, | |
}, | |
}, | |
authorizing: { | |
on: { | |
CMD_AUTH: { | |
actions: ['clearPrevAuthFlow', 'initAuthFlow'], | |
}, | |
SYNC_AUTHORIZED: { | |
target: 'authorized', | |
}, | |
AUTH_SUCCESS: { | |
target: 'authorized', | |
actions: ['notifyAuthorized'], | |
}, | |
AUTH_FAILURE: { | |
target: 'unauthorized', | |
}, | |
}, | |
}, | |
authorized: { | |
on: { | |
CMD_UNAUTH: { | |
target: 'unauthorizing', | |
actions: ['initUnAuthFlow'], | |
}, | |
SYNC_REFRESHED: { | |
}, | |
SYNC_UNAUTHORIZED: { | |
target: 'unauthorized', | |
}, | |
EXPIRE_THRESHOULD_REACHED: { | |
actions: ['refresh'], | |
}, | |
REFRESH_SUCCESS: { // expiry preventive refresh. | |
actions: ['notifyRefreshed'], | |
}, | |
EXPIRED: { | |
target: 'expired', | |
}, | |
}, | |
}, | |
unauthorizing: { | |
on: { | |
CMD_UNAUTH: { | |
actions: ['clearPrevUnAuthFlow', 'initUnAuthFlow'], | |
}, | |
SYNC_UNAUTHORIZED: { | |
target: 'unauthorized', | |
actions: ['clearPrevUnAuthFlow'], | |
}, | |
UNAUTH_SUCCESS: { | |
target: 'unauthorized', | |
actions: ['notifyUnAuthorized'], | |
}, | |
UNAUTH_FAILURE: { | |
target: 'authorized', // NOTE!! possible that he may came here from 'expired' state instead | |
}, | |
}, | |
}, | |
expired: { | |
entry: ['initRefreshFlow'], | |
on: { | |
CMD_UNAUTH: { | |
target: 'unauthorizing', | |
actions: ['initUnAuthFlow'], | |
}, | |
SYNC_UNAUTHORIZED: { | |
target: 'unauthorized', | |
}, | |
SYNC_REFRESHED: { | |
target: 'authorized', | |
}, | |
CMD_REFRESH: { | |
actions: ['initRefreshFlow'], // is an inPage op. | |
}, | |
REFRESH_SUCCESS: { | |
target: 'authorized', | |
actions: ['notifyRefreshed'], | |
}, | |
REFRESH_FAILURE: { | |
actions: ['initRefreshFlow'], | |
}, | |
CLEAR: { | |
target: 'unauthorized', | |
actions: ['clearOldSession'], | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment