logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
8.15k stars 395 forks source link

feat(core,schemas): implement the sie settings guard #6215

Closed simeng-li closed 1 month ago

simeng-li commented 1 month ago

Summary

Please ignore the largest PR size, have of them are ut test cases definitions.

This PR includes the following update:

Remove the InteractionIdentifierType enum definitions in @logto/schema

Previously we had a new InteractionIdentifierType enum value defined. To represent the type of identifiers supported in Logto. username, email, and phone. It turns out, we have had a SignInIdentifier enum defined already with the exact same definition, and being used in the sign-in-experience settings. Thus, remove the new InteractionIdentifierType definition, and replace all the references using SignInIdentifier.

Remove the session.not_identified error code and replace it with the existing session.identifier_not_found

We had a new session.not_identified error code defined for the experience API. For a similar reason as above, we already have a session.identifier_not_found defined and used in the current interaction API. It represents the same exception case. Remove the duplicate session.not_identified.

Implement new SignInExperienceSettings class for sie settings validation user

This class will read the signInExperience settings from DB and provide multiple verification method validations methods:

Update the ExperienceSession.setInteractionEvent method

Refactor the ExperienceSession.identifyUser method.

Testing

UT case added.

Checklist

github-actions[bot] commented 1 month ago

COMPARE TO master

Total Size Diff :warning: :chart_with_upwards_trend: +22.2 KB

Diff by File |Name|Diff| |---|---| |packages/core/src/routes/experience/classes/experience-interaction.ts|:chart_with_upwards_trend: +1.6 KB| |packages/core/src/routes/experience/classes/utils.ts|:chart_with_upwards_trend: +1.41 KB| |packages/core/src/routes/experience/classes/validators/sign-in-experience-validator.test.ts|:warning: :chart_with_upwards_trend: +15.5 KB| |packages/core/src/routes/experience/classes/validators/sign-in-experience-validator.ts|:chart_with_upwards_trend: +6.71 KB| |packages/core/src/routes/experience/classes/verifications/code-verification.ts|:chart_with_upwards_trend: +126 Bytes| |packages/core/src/routes/experience/index.ts|:chart_with_upwards_trend: +187 Bytes| |packages/core/src/routes/experience/verification-routes/backup-code-verification.ts|:chart_with_upwards_trend: +6 Bytes| |packages/core/src/routes/experience/verification-routes/totp-verification.ts|:chart_with_upwards_trend: +12 Bytes| |packages/core/src/routes/experience/verification-routes/verification-code.ts|:chart_with_upwards_trend: +48 Bytes| |packages/integration-tests/src/helpers/experience/index.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/interaction.test.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/password.test.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/sign-in-interaction/verification-code.test.ts|:chart_with_upwards_trend: +50 Bytes| |packages/integration-tests/src/tests/api/experience-api/verifications/backup-code-verification.test.ts|:chart_with_upwards_trend: +6 Bytes| |packages/integration-tests/src/tests/api/experience-api/verifications/password-verification.test.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/verifications/social-verification.test.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/verifications/totp-verification.test.ts|:chart_with_upwards_trend: +18 Bytes| |packages/integration-tests/src/tests/api/experience-api/verifications/verification-code.test.ts|:chart_with_upwards_trend: +27 Bytes| |packages/phrases/src/locales/en/errors/session.ts|:chart_with_upwards_trend: +64 Bytes| |packages/schemas/src/types/interactions.ts|:chart_with_upwards_trend: +132 Bytes|