-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
90 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
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,30 @@ | ||
import { z } from "zod"; | ||
|
||
const registrationSchema = z.object({ | ||
email: z.string().trim().email(), | ||
age: z.number().min(18, "You must be at least 18 years old"), | ||
}); | ||
|
||
export default definePrecognitionEventHandler(registrationSchema, async (event) => { | ||
// This handler function won't run on precognition requests! | ||
// It will only run on actual form submissions. | ||
|
||
// validate the input | ||
// This will throw a validation error response if the input is invalid | ||
const validated = await getValidatedInput(event, registrationSchema); | ||
|
||
// do something with the body | ||
const newUser = { | ||
id: 1, | ||
email: validated.email, | ||
}; | ||
|
||
// simulate a slow response to show the loading state o the front-end | ||
await sleep(1000); | ||
|
||
return newUser; | ||
}); | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
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,27 @@ | ||
import { z } from "zod"; | ||
|
||
const registrationSchema = z.object({ | ||
email: z.string().trim().email(), | ||
age: z.number().min(18, "You must be at least 18 years old"), | ||
}); | ||
|
||
export default defineEventHandler(async (event) => { | ||
// validate the input | ||
// This will throw a validation error response if the input is invalid | ||
const validated = await getValidatedInput(event, registrationSchema); | ||
|
||
// do something with the body | ||
const newUser = { | ||
id: 1, | ||
email: validated.email, | ||
}; | ||
|
||
// simulate a slow response to show the loading state o the front-end | ||
await sleep(1000); | ||
|
||
return newUser; | ||
}); | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.