Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhanced registration form validation #81

Merged
merged 8 commits into from
Nov 7, 2023

Conversation

mark-omarov
Copy link
Contributor

@mark-omarov mark-omarov commented Nov 3, 2023

Close #44

  • /register/password API validation with zod and zod-express-middleware.
  • API will respond instead of redirect. Mainly for displaying validation and business logic errors without query params.
  • FE AuthPage will keep using original /login/password API with redirect, for register action a request will be made instead
  • Updated test to match implementation
  • Updated validation rules as discussed here - feat(app): enhanced registration form validation #44 (comment)

Things I considered but decided to omit:

  • Keep redirects and use query params for erros: validation errors should not be in query params
  • Update /login/password to drop redirect: might be a good idea, but not in the context of this issue
  • Break form into login and registration: perhaps later
  • Refactor and restructuring: same above - more of a tech debt than feature related

Add zod validation for registration password
and use zod-express-middleware for request
validation
Copy link

changeset-bot bot commented Nov 3, 2023

🦋 Changeset detected

Latest commit: 3ef254c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hyperdx/api Minor
@hyperdx/app Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mark-omarov mark-omarov changed the title feat(app): enhanced registration form validation feat(app,api): enhanced registration form validation Nov 3, 2023
@mark-omarov mark-omarov changed the title feat(app,api): enhanced registration form validation feat: enhanced registration form validation Nov 3, 2023
@mark-omarov mark-omarov marked this pull request as ready for review November 3, 2023 12:35

const onSubmit: SubmitHandler<FormData> = async data => {
try {
const response = await fetch(`${API_SERVER_URL}/register/password`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice if we can wrap the api call using react query (check out api.ts file)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed that, my bad
updated now!


if (Array.isArray(jsonData) && jsonData[0]?.errors?.issues) {
return jsonData[0].errors.issues.forEach((issue: any) => {
setError(issue.path[0], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

type="password"
className="border-0"
{...form.password}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not super critical. I think it would be nice to add 'confirm password' field and the icon to toggle 'show password'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's #40 which adds the toggle, perhaps I shouldn't duplicate it
I'm down to add the password confirmation field, but not sure if I get to it today or tomorrow, feel free to go ahead and merge it, and I can implement it sometime this week with a follow-up PR. This will also give you some time figure out if you proceed with #40 or not. How does that sound?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. let me merge the pr and we can implement these features later. thanks

Copy link
Contributor

@wrn14897 wrn14897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great stuff. Thanks for making the changes!

@kodiakhq kodiakhq bot merged commit 7d636f2 into hyperdxio:main Nov 7, 2023
3 checks passed
@mark-omarov mark-omarov deleted the feat/auth-form-validation branch November 7, 2023 21:59
kodiakhq bot pushed a commit that referenced this pull request Nov 9, 2023
Origin: #81 (comment)

Add a password confirmation field to the registration form.

- API will require `confirmPassword` field on the registration endpoint
- The `confirmPassword` and `password` fields will be validated by zod on API validation
- UI on the registration form will have a "Confirm Password" field
- Validation errors will be displayed on the UI the same way other validation errors
- API test covers mismatch between `confirmPassword` and `password` (simple check, can be improved)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(app): enhanced registration form validation
2 participants