11import { Auth } from 'aws-amplify' ;
22import get from 'lodash/get' ;
33import pickBy from 'lodash/pickBy' ;
4- import { createMachine , sendUpdate } from 'xstate' ;
4+ import { assign , createMachine , sendUpdate } from 'xstate' ;
55
66import { AuthEvent , SignUpContext } from '../../types' ;
77import { runValidators } from '../../validators' ;
@@ -132,16 +132,9 @@ export function createSignUpMachine({ services }: SignUpMachineOptions) {
132132 } ,
133133 } ,
134134 skipConfirm : {
135- invoke : {
136- src : 'signIn' ,
137- onDone : {
138- target : '#signUpActor.resolved' ,
139- actions : 'setUser' ,
140- } ,
141- onError : {
142- target : 'idle' ,
143- actions : 'setRemoteError' ,
144- } ,
135+ always : {
136+ target : '#signUpActor.resolved' ,
137+ actions : 'setAutoSignInIntent' ,
145138 } ,
146139 } ,
147140
@@ -174,7 +167,7 @@ export function createSignUpMachine({ services }: SignUpMachineOptions) {
174167 onError : [
175168 {
176169 target : '#signUpActor.resolved' ,
177- actions : 'setUser ' ,
170+ actions : 'setAutoSignInIntent ' ,
178171 cond : 'isUserAlreadyConfirmed' ,
179172 } ,
180173 { target : 'edit' , actions : 'setRemoteError' } ,
@@ -188,7 +181,7 @@ export function createSignUpMachine({ services }: SignUpMachineOptions) {
188181 src : 'confirmSignUp' ,
189182 onDone : {
190183 target : '#signUpActor.resolved' ,
191- actions : [ 'setUser' ] ,
184+ actions : 'setAutoSignInIntent' ,
192185 } ,
193186 onError : { target : 'edit' , actions : 'setRemoteError' } ,
194187 } ,
@@ -203,6 +196,7 @@ export function createSignUpMachine({ services }: SignUpMachineOptions) {
203196 return {
204197 user : get ( event , 'data.user' ) || context . user ,
205198 authAttributes : { username, password } ,
199+ intent : context . intent ,
206200 } ;
207201 } ,
208202 } ,
@@ -247,28 +241,17 @@ export function createSignUpMachine({ services }: SignUpMachineOptions) {
247241 setCodeDeliveryDetails,
248242 setUser,
249243 sendUpdate : sendUpdate ( ) , // sendUpdate is a HOC
244+ setAutoSignInIntent : assign ( { intent : ( _ ) => 'autoSignIn' } ) ,
250245 } ,
251246 services : {
252- async signIn ( context , event ) {
253- const { user, authAttributes, formValues } = context ;
254-
255- const username =
256- get ( user , 'username' ) || get ( authAttributes , 'username' ) ;
257- const password = get ( formValues , 'password' ) ;
258-
259- return await Auth . signIn ( username , password ) ;
260- } ,
261247 async confirmSignUp ( context , event ) {
262248 const { user, authAttributes, formValues } = context ;
263249 const { confirmation_code : code } = formValues ;
264250
265251 const username =
266252 get ( user , 'username' ) || get ( authAttributes , 'username' ) ;
267- const { password } = authAttributes ;
268-
269- await services . handleConfirmSignUp ( { username, code } ) ;
270253
271- return await Auth . signIn ( username , password ) ;
254+ return await services . handleConfirmSignUp ( { username, code } ) ;
272255 } ,
273256 async resendConfirmationCode ( context , event ) {
274257 const { user, authAttributes } = context ;
0 commit comments