Created
April 4, 2021 15:36
-
-
Save jermsam/8f6968c01be72f4f4aee53dfadef6758 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 passwordlessAuth = Machine({ | |
id: 'passwordless', | |
initial: 'requestPhase', | |
context: { | |
phone: '', | |
hash:'', | |
otp:'' | |
}, | |
// main - states | |
states:{ | |
requestPhase:{ | |
id:'requestPhase', | |
initial:'noPhone', | |
states:{ | |
noPhone:{ | |
on:{ | |
SET_PHONE:{ | |
actions:['setPhone'] | |
}, | |
REQUEST_OTP:{ | |
target:'requestingOtp' | |
} | |
} | |
}, | |
requestingOtp:{ | |
invoke:{ | |
src:'requestOtp', | |
onError:'noPhone', | |
onDone:{ | |
target:'#verifyPhase' | |
}, | |
} | |
} | |
} | |
}, | |
verifyPhase:{ | |
id:'verifyPhase', | |
initial:'noOtp', | |
states:{ | |
noOtp:{ | |
on:{ | |
SET_OTP:{ | |
actions:['setOTP'] | |
}, | |
VERIFY_OTP:{ | |
target:'verifyingOtp' | |
} | |
} | |
}, | |
verifyingOtp:{ | |
invoke:{ | |
src:'verifyingOTP', | |
onDone:{ | |
target:'loggedin' | |
}, | |
onError:{ | |
target:'#requestPhase.requestingOtp' | |
} | |
} | |
}, | |
loggedin:{ | |
type:'final' | |
} | |
} | |
}, | |
} | |
}, | |
// actions | |
{ | |
actions:{ | |
setPhone:assign({ | |
phone:(ctx,value)=>ctx.phone=value | |
}), | |
setOTP:assign({ | |
otp:(ctx,value)=>ctx.otp=value | |
}) | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment