-
-
Notifications
You must be signed in to change notification settings - Fork 447
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 verification code flow (migration-…
…2) (#6408) * refactor(experience): refactor the verificaiton code flow refactor the verification code flow * refactor(experience): migrate the social and sso flow (migration-3) (#6406) * refactor(experience): migrate the social and sso flow migrate the social and sso flow * refactor(experience): migrate profile fulfillment flow (migration-4) (#6414) * refactor(experience): migrate profile fulfillment flow migrate the profile fulfillment flow * refactor(experience): remove unused hook remove unused hook * fix(experience): fix password policy checker fix password policy checker error display * fix(experience): fix the api name fix the api name * refactor(experience): migrate mfa flow (migration-5) (#6417) * refactor(experience): migrate mfa binding flow migrate mfa binding flow * test(experience): update unit tests (migration-6) (#6420) * test(experience): update unit tests update unit tests * chore(experience): remove legacy APIs remove legacy APIs * refactor(experience): revert api prefix revert api prefix * fix(experience): update the sso connectors endpoint update the sso connectors endpoint
- Loading branch information
Showing
76 changed files
with
1,732 additions
and
1,129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const kyPrefixUrl = '/'; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const prefix = '/api/experience'; | ||
|
||
export const experienceApiRoutes = Object.freeze({ | ||
prefix, | ||
identification: `${prefix}/identification`, | ||
submit: `${prefix}/submit`, | ||
verification: `${prefix}/verification`, | ||
profile: `${prefix}/profile`, | ||
mfa: `${prefix}/profile/mfa`, | ||
}); | ||
|
||
export type VerificationResponse = { | ||
verificationId: string; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { | ||
InteractionEvent, | ||
type PasswordVerificationPayload, | ||
SignInIdentifier, | ||
type VerificationCodeIdentifier, | ||
} from '@logto/schemas'; | ||
|
||
import { type ContinueFlowInteractionEvent } from '@/types'; | ||
|
||
import api from '../api'; | ||
|
||
import { experienceApiRoutes, type VerificationResponse } from './const'; | ||
import { | ||
initInteraction, | ||
identifyUser, | ||
submitInteraction, | ||
updateInteractionEvent, | ||
_updateProfile, | ||
identifyAndSubmitInteraction, | ||
} from './interaction'; | ||
|
||
export { | ||
initInteraction, | ||
submitInteraction, | ||
identifyUser, | ||
identifyAndSubmitInteraction, | ||
} from './interaction'; | ||
|
||
export * from './mfa'; | ||
export * from './social'; | ||
|
||
export const registerWithVerifiedIdentifier = async (verificationId: string) => { | ||
await updateInteractionEvent(InteractionEvent.Register); | ||
return identifyAndSubmitInteraction({ verificationId }); | ||
}; | ||
|
||
export const signInWithVerifiedIdentifier = async (verificationId: string) => { | ||
await updateInteractionEvent(InteractionEvent.SignIn); | ||
return identifyAndSubmitInteraction({ verificationId }); | ||
}; | ||
|
||
// Password APIs | ||
export const signInWithPasswordIdentifier = async (payload: PasswordVerificationPayload) => { | ||
await initInteraction(InteractionEvent.SignIn); | ||
|
||
const { verificationId } = await api | ||
.post(`${experienceApiRoutes.verification}/password`, { | ||
json: payload, | ||
}) | ||
.json<VerificationResponse>(); | ||
|
||
return identifyAndSubmitInteraction({ verificationId }); | ||
}; | ||
|
||
export const registerWithUsername = async (username: string) => { | ||
await initInteraction(InteractionEvent.Register); | ||
|
||
return _updateProfile({ type: SignInIdentifier.Username, value: username }); | ||
}; | ||
|
||
export const continueRegisterWithPassword = async (password: string) => { | ||
await _updateProfile({ type: 'password', value: password }); | ||
|
||
return identifyAndSubmitInteraction(); | ||
}; | ||
|
||
// Verification code APIs | ||
type VerificationCodePayload = { | ||
identifier: VerificationCodeIdentifier; | ||
code: string; | ||
verificationId: string; | ||
}; | ||
|
||
export const sendVerificationCode = async ( | ||
interactionEvent: InteractionEvent, | ||
identifier: VerificationCodeIdentifier | ||
) => | ||
api | ||
.post(`${experienceApiRoutes.verification}/verification-code`, { | ||
json: { | ||
interactionEvent, | ||
identifier, | ||
}, | ||
}) | ||
.json<VerificationResponse>(); | ||
|
||
const verifyVerificationCode = async (json: VerificationCodePayload) => | ||
api | ||
.post(`${experienceApiRoutes.verification}/verification-code/verify`, { | ||
json, | ||
}) | ||
.json<VerificationResponse>(); | ||
|
||
export const identifyWithVerificationCode = async (json: VerificationCodePayload) => { | ||
const { verificationId } = await verifyVerificationCode(json); | ||
return identifyAndSubmitInteraction({ verificationId }); | ||
}; | ||
|
||
// Profile APIs | ||
|
||
export const updateProfileWithVerificationCode = async ( | ||
json: VerificationCodePayload, | ||
interactionEvent?: ContinueFlowInteractionEvent | ||
) => { | ||
const { verificationId } = await verifyVerificationCode(json); | ||
|
||
const { | ||
identifier: { type }, | ||
} = json; | ||
|
||
await _updateProfile({ | ||
type, | ||
verificationId, | ||
}); | ||
|
||
if (interactionEvent === InteractionEvent.Register) { | ||
await identifyUser(); | ||
} | ||
|
||
return submitInteraction(); | ||
}; | ||
|
||
type UpdateProfilePayload = { | ||
type: SignInIdentifier.Username | 'password'; | ||
value: string; | ||
}; | ||
|
||
export const updateProfile = async ( | ||
payload: UpdateProfilePayload, | ||
interactionEvent: ContinueFlowInteractionEvent | ||
) => { | ||
await _updateProfile(payload); | ||
|
||
if (interactionEvent === InteractionEvent.Register) { | ||
await identifyUser(); | ||
} | ||
|
||
return submitInteraction(); | ||
}; | ||
|
||
export const resetPassword = async (password: string) => { | ||
await api.put(`${experienceApiRoutes.profile}/password`, { | ||
json: { | ||
password, | ||
}, | ||
}); | ||
|
||
return submitInteraction(); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
type InteractionEvent, | ||
type IdentificationApiPayload, | ||
type UpdateProfileApiPayload, | ||
} from '@logto/schemas'; | ||
|
||
import api from '../api'; | ||
|
||
import { experienceApiRoutes } from './const'; | ||
|
||
type SubmitInteractionResponse = { | ||
redirectTo: string; | ||
}; | ||
|
||
export const initInteraction = async (interactionEvent: InteractionEvent) => | ||
api.put(`${experienceApiRoutes.prefix}`, { | ||
json: { | ||
interactionEvent, | ||
}, | ||
}); | ||
|
||
export const identifyUser = async (payload: IdentificationApiPayload = {}) => | ||
api.post(experienceApiRoutes.identification, { json: payload }); | ||
|
||
export const submitInteraction = async () => | ||
api.post(`${experienceApiRoutes.submit}`).json<SubmitInteractionResponse>(); | ||
|
||
export const _updateProfile = async (payload: UpdateProfileApiPayload) => | ||
api.post(experienceApiRoutes.profile, { json: payload }); | ||
|
||
export const updateInteractionEvent = async (interactionEvent: InteractionEvent) => | ||
api.put(`${experienceApiRoutes.prefix}/interaction-event`, { | ||
json: { | ||
interactionEvent, | ||
}, | ||
}); | ||
|
||
export const identifyAndSubmitInteraction = async (payload?: IdentificationApiPayload) => { | ||
await identifyUser(payload); | ||
return submitInteraction(); | ||
}; |
Oops, something went wrong.