Skip to content

Commit

Permalink
missing validation for refill amount
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelUnkey committed Jan 9, 2025
1 parent 9bd0d92 commit 4307ecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ export const UpdateKeyRemaining: React.FC<Props> = ({ apiKey }) => {
if (values.refill?.interval === "none") {
delete values.refill;
}

// make sure they aren't sent to the server if they are disabled.
if (values.refill?.interval !== "none" && !values.refill?.amount) {
form.setError("refill.amount", {
type: "manual",
message: "Please enter a value if interval is selected",
});
return;
}
if (!values.refill?.amount && values.refill?.refillDay && values.limitEnabled) {
form.setError("refill.amount", {
message: "Please enter the number of uses per interval or remove the refill day",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ export const CreateKey = ({ apiId, keyAuthId, defaultBytes, defaultPrefix }: Pro
});

async function onSubmit(values: z.infer<typeof formSchema>) {
// make sure they aren't sent to the server if they are disabled.
if (values.limit?.refill?.interval !== "none" && !values.limit?.refill?.amount) {
form.setError("limit.refill.amount", {
type: "manual",
message: "Please enter a value if interval is selected",
});
return;
}
if (!values.expireEnabled) {
delete values.expires;
}
Expand Down

0 comments on commit 4307ecc

Please sign in to comment.