2022-03-25 18:37:51 +00:00
|
|
|
import { withValidation } from "next-validations";
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
const schemaApiKey = z
|
|
|
|
.object({
|
2022-03-26 04:28:53 +00:00
|
|
|
// We need to cast the date as strings as when we get it from the json response
|
|
|
|
// we serve in api it is a string too (JSON doesn't directly support Date types)
|
|
|
|
createdAt: z.date().optional().or(z.string().optional()),
|
2022-03-26 00:40:43 +00:00
|
|
|
expiresAt: z.date().optional(), // default is 30 days
|
2022-03-25 18:37:51 +00:00
|
|
|
note: z.string().min(1).optional(),
|
|
|
|
})
|
2022-03-26 23:58:22 +00:00
|
|
|
.strict();
|
|
|
|
|
2022-03-25 18:37:51 +00:00
|
|
|
const withValidApiKey = withValidation({
|
|
|
|
schema: schemaApiKey,
|
|
|
|
type: "Zod",
|
|
|
|
mode: "body",
|
|
|
|
});
|
|
|
|
|
|
|
|
export { schemaApiKey, withValidApiKey };
|