-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experience): refactor the verificaiton code flow
refactor the verification code flow
- Loading branch information
Showing
19 changed files
with
495 additions
and
241 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
import { InteractionEvent } from '@logto/schemas'; | ||
import { InteractionEvent, type VerificationCodeIdentifier } from '@logto/schemas'; | ||
|
||
import { UserFlow } from '@/types'; | ||
|
||
import type { SendVerificationCodePayload } from './interaction'; | ||
import { putInteraction, sendVerificationCode } from './interaction'; | ||
import { initInteraction, sendVerificationCode } from './experience'; | ||
|
||
/** Move to API */ | ||
export const sendVerificationCodeApi = async ( | ||
type: UserFlow, | ||
payload: SendVerificationCodePayload | ||
identifier: VerificationCodeIdentifier | ||
) => { | ||
if (type === UserFlow.ForgotPassword) { | ||
await putInteraction(InteractionEvent.ForgotPassword); | ||
} | ||
|
||
if (type === UserFlow.SignIn) { | ||
await putInteraction(InteractionEvent.SignIn); | ||
switch (type) { | ||
case UserFlow.SignIn: { | ||
await initInteraction(InteractionEvent.SignIn); | ||
return sendVerificationCode(InteractionEvent.SignIn, identifier); | ||
} | ||
case UserFlow.Register: { | ||
await initInteraction(InteractionEvent.Register); | ||
return sendVerificationCode(InteractionEvent.Register, identifier); | ||
} | ||
case UserFlow.ForgotPassword: { | ||
await initInteraction(InteractionEvent.ForgotPassword); | ||
return sendVerificationCode(InteractionEvent.ForgotPassword, identifier); | ||
} | ||
case UserFlow.Continue: { | ||
// Continue flow does not have its own email template, always use sign-in template for now | ||
return sendVerificationCode(InteractionEvent.SignIn, identifier); | ||
} | ||
} | ||
}; | ||
|
||
if (type === UserFlow.Register) { | ||
await putInteraction(InteractionEvent.Register); | ||
export const resendVerificationCodeApi = async ( | ||
type: UserFlow, | ||
identifier: VerificationCodeIdentifier | ||
) => { | ||
switch (type) { | ||
case UserFlow.SignIn: { | ||
return sendVerificationCode(InteractionEvent.SignIn, identifier); | ||
} | ||
case UserFlow.Register: { | ||
return sendVerificationCode(InteractionEvent.Register, identifier); | ||
} | ||
case UserFlow.ForgotPassword: { | ||
return sendVerificationCode(InteractionEvent.ForgotPassword, identifier); | ||
} | ||
case UserFlow.Continue: { | ||
// Continue flow does not have its own email template, always use sign-in template for now | ||
return sendVerificationCode(InteractionEvent.SignIn, identifier); | ||
} | ||
} | ||
|
||
return sendVerificationCode(payload); | ||
}; |
Oops, something went wrong.