Created
June 2, 2020 17:09
-
-
Save wmcbain/e57c1f6a7c412824caafe86b95106490 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 authMachine = Machine({ | |
id: 'auth_machine', | |
initial: 'authIsLoading', | |
context: { | |
sessionToken: null, | |
}, | |
states: { | |
authIsLoading: { | |
on: { | |
LOGGED_IN: 'isLoggedIn', | |
NOT_LOGGED_IN: 'waitForUserChoice', | |
}, | |
}, | |
biometricsAuth: { | |
initial: 'attemptBiometrics', | |
onDone: 'isLoggedIn', | |
on: { | |
BIOMETRICS_ERROR: 'waitForUserChoice', | |
CANCEL: 'waitForUserChoice', | |
}, | |
states: { | |
attemptBiometrics: { | |
on: { | |
HAS_BIOMETRICS: 'loginBiometrics', | |
USE_PIN_FALLBACK: 'loginPin', | |
}, | |
}, | |
loginBiometrics: { | |
on: { | |
USE_PIN_FALLBACK: 'loginPin', | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
loginPin: { | |
on: { | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
authenticated: { | |
type: 'final', | |
}, | |
}, | |
}, | |
isLoggedIn: { | |
entry: 'redirectToHomeScreen', | |
on: { | |
LOG_OUT: 'logout', | |
}, | |
}, | |
waitForUserChoice: { | |
on: { | |
BD_USER_DEEPLINK_CAPTURED: 'verifyBDUser', | |
DEEPLINK_CAPTURED: 'registerNewUser', | |
LOG_IN: 'login', | |
MIGRATE_BD_USER: 'loginBDUser', | |
REGISTER_NEW_USER_PHONE_NUMBER: 'registerNewUserPhoneNumber', | |
RESET_PASSWORD_DEEPLINK_CAPTURED: 'resetPassword', | |
}, | |
}, | |
login: { | |
initial: 'userLogin', | |
onDone: 'isLoggedIn', | |
on: { | |
FORGOT_PASSWORD: 'forgotPassword', | |
CANCEL: 'waitForUserChoice', | |
}, | |
states: { | |
userLogin: { | |
entry: 'redirectToLoginScreen', | |
on: { | |
USER_AUTHENTICATED: 'authenticateUser', | |
LOGIN_ERROR: 'userLogin', | |
}, | |
}, | |
authenticateUser: { | |
entry: 'authenticateUser', | |
on: { | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
authenticated: { | |
type: 'final', | |
}, | |
}, | |
}, | |
loginBDUser: { | |
entry: 'redirectToLoginBD', | |
initial: 'bdLogin', | |
onDone: 'waitForUserChoice', | |
on: { | |
CANCEL: 'waitForUserChoice', | |
REQUEST_MIGRATION: 'requestMigration', | |
}, | |
states: { | |
bdLogin: { | |
on: { | |
LOGGED_INTO_BD: 'routeBDUser', | |
}, | |
}, | |
routeBDUser: { | |
entry: 'routeBDUser', | |
on: { | |
IS_EXISTING_ALLE_MEMBER: 'isExistingAlleMember', | |
MIGRATE_PHONE_NUMBER: 'migratePhoneNumber', | |
HAS_PHONE_NUMBER: 'hasPhoneNumber', | |
}, | |
}, | |
isExistingAlleMember: { | |
on: { | |
RETRY_BD_LOGIN: 'bdLogin', | |
}, | |
}, | |
migratePhoneNumber: { | |
entry: ['setSessionToken', 'redirectToRegisterPhone'], | |
on: { | |
PHONE_NUMBER_SUBMITTED: 'submitPhoneNumber', | |
}, | |
}, | |
submitPhoneNumber: { | |
entry: 'redirectToHomeScreen', | |
type: 'final', | |
}, | |
hasPhoneNumber: { | |
entry: 'setSessionToken', | |
}, | |
}, | |
}, | |
registrationCancelled: { | |
entry: 'redirectToHomeScreen', | |
on: { | |
'': 'waitForUserChoice', | |
}, | |
}, | |
requestBiometrics: { | |
entry: 'redirectToHomeScreen', | |
initial: 'waitForSystemPrompt', | |
onDone: 'isLoggedIn', | |
states: { | |
waitForSystemPrompt: { | |
on: { | |
BIOMETRICS_PROVIDED: 'biometricsProvided', | |
BIOMETRICS_CANCELLED: 'biometricsFinished', | |
}, | |
}, | |
biometricsProvided: { | |
on: { | |
CREDENTIALS_SAVED: 'biometricsFinished', | |
}, | |
}, | |
biometricsFinished: { | |
type: 'final', | |
}, | |
}, | |
}, | |
verifyBDUser: { | |
initial: 'verifyPhoneNumber', | |
onDone: 'requestMigration', | |
states: { | |
verifyPhoneNumber: { | |
entry: 'verifyBDPhoneNumber', | |
on: { | |
BD_USER_PHONE_VERIFIED: 'phoneNumberVerified', | |
}, | |
}, | |
phoneNumberVerified: { | |
type: 'final', | |
}, | |
}, | |
}, | |
requestMigration: { | |
entry: 'redirectToRequestMigrationScreen', | |
on: { | |
SUBMIT_MIGRATION: 'migrateBDUser', | |
CANCEL: 'waitForUserChoice', | |
}, | |
}, | |
migrateBDUser: { | |
initial: 'startBDMigration', | |
onDone: 'requestBiometrics', | |
on: { | |
MIGRATION_ERROR: 'requestMigration', | |
CANCEL: 'registrationCancelled', | |
}, | |
states: { | |
startBDMigration: { | |
entry: 'redirectToBDMigrationScreen', | |
on: { | |
REGISTER_BD_USER: 'registerBDUser', | |
TOO_MANY_ATTEMPTS: 'lockMigration', | |
}, | |
}, | |
lockMigration: {}, | |
registerBDUser: { | |
entry: 'redirectToRegisterBDUserScreen', | |
on: { | |
USER_REGISTERED: 'registrationComplete', | |
}, | |
}, | |
registrationComplete: { | |
entry: 'authenticateUser', | |
on: { | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
authenticated: { | |
type: 'final', | |
}, | |
}, | |
}, | |
registerNewUserPhoneNumber: { | |
initial: 'registerPhoneNumber', | |
onDone: 'waitForUserChoice', | |
on: { | |
CANCEL: 'waitForUserChoice', | |
}, | |
states: { | |
registerPhoneNumber: { | |
entry: 'redirectToRegisterPhone', | |
on: { | |
PHONE_NUMBER_SUBMITTED: 'submitPhoneNumber', | |
}, | |
}, | |
submitPhoneNumber: { | |
entry: 'redirectToHomeScreen', | |
type: 'final', | |
}, | |
}, | |
}, | |
registerNewUser: { | |
initial: 'verifyPhoneNumber', | |
onDone: 'requestBiometrics', | |
on: { | |
INVALID_CODE_ERROR: 'invalidCode', | |
CANCEL: 'registrationCancelled', | |
}, | |
states: { | |
verifyPhoneNumber: { | |
entry: 'verifyPhoneNumber', | |
on: { | |
REGISTER_USER: 'registerUser', | |
}, | |
}, | |
registerUser: { | |
entry: 'setSessionToken', | |
on: { | |
USER_REGISTERED: 'registrationComplete', | |
}, | |
}, | |
registrationComplete: { | |
entry: 'authenticateUser', | |
on: { | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
authenticated: { | |
type: 'final', | |
}, | |
}, | |
}, | |
invalidCode: { | |
entry: 'redirectToHomeScreen', | |
on: { | |
INVALID_CODE_ERROR_HANDLED: 'waitForUserChoice', | |
}, | |
}, | |
forgotPassword: { | |
initial: 'submitUsername', | |
on: { | |
CANCEL: 'waitForUserChoice', | |
LOG_IN: 'login', | |
}, | |
onDone: 'waitForUserChoice', | |
states: { | |
submitUsername: { | |
entry: 'redirectToForgotPasswordScreen', | |
on: { | |
USERNAME_SUBMITTED: 'codeRequested', | |
}, | |
}, | |
codeRequested: { | |
entry: 'redirectToHomeScreen', | |
type: 'final', | |
}, | |
}, | |
}, | |
resetPassword: { | |
initial: 'verifyResetPasswordToken', | |
onDone: 'isLoggedIn', | |
on: { | |
CANCEL: 'waitForUserChoice', | |
}, | |
states: { | |
verifyResetPasswordToken: { | |
entry: 'verifyResetPasswordToken', | |
on: { | |
VERIFIED_RESET_PASSWORD_TOKEN: 'createNewPassword', | |
RESET_PASSWORD_TOKEN_ERROR: 'resetPasswordError', | |
}, | |
}, | |
createNewPassword: { | |
entry: 'setSessionToken', | |
on: { | |
PASSWORD_CHANGED: 'authenticateUser', | |
}, | |
}, | |
resetPasswordError: {}, | |
authenticateUser: { | |
entry: 'authenticateUser', | |
on: { | |
USER_AUTHENTICATED: 'authenticated', | |
}, | |
}, | |
authenticated: { | |
type: 'final', | |
}, | |
}, | |
}, | |
logout: { | |
initial: 'oktaLogout', | |
onDone: 'waitForUserChoice', | |
on: { | |
CANCEL: 'isLoggedIn', | |
}, | |
states: { | |
oktaLogout: { | |
entry: 'startOktaLogout', | |
on: { | |
USER_LOGGED_OUT: 'loggedOut', | |
}, | |
}, | |
loggedOut: { | |
type: 'final', | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment