Skip to content

Commit

Permalink
chore: add validator to ip field
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddyDevelop committed Nov 11, 2024
1 parent 297fde0 commit 86b4cea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/dto/admin/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package admin
type CreateSessionTokenDto struct {
UserID string `json:"user_id" validate:"required,uuid4"`
UserAgent string `json:"user_agent"`
IpAddress string `json:"ip_address"`
IpAddress string `json:"ip_address" validate:"omitempty,ip"`
}

type CreateSessionTokenResponse struct {
Expand Down
2 changes: 2 additions & 0 deletions backend/dto/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (cv *CustomValidator) Validate(i interface{}) error {
vErrs[i] = fmt.Sprintf("%s entries are not unique", err.Field())
case "hanko_event":
vErrs[i] = fmt.Sprintf("%s in %s is not a valid webhook event", err.Value(), err.Field())
case "ip":
vErrs[i] = fmt.Sprintf("%s must be a valid ip address (v4 or v6)", err.Field())
default:
vErrs[i] = fmt.Sprintf("something wrong on %s; %s", err.Field(), err.Tag())
}
Expand Down

0 comments on commit 86b4cea

Please sign in to comment.