Skip to content

Instantly share code, notes, and snippets.

@jermsam
Created April 4, 2021 15:36
Show Gist options
  • Save jermsam/8f6968c01be72f4f4aee53dfadef6758 to your computer and use it in GitHub Desktop.
Save jermsam/8f6968c01be72f4f4aee53dfadef6758 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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