File tree Expand file tree Collapse file tree 1 file changed +5
-11
lines changed
Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
44import stableStringify from "json-stable-stringify" ;
55import { json } from "@remix-run/server-runtime" ;
66import { redirect , typedjson , useTypedLoaderData } from "remix-typedjson" ;
7+ import { z } from "zod" ;
78import { prisma } from "~/db.server" ;
89import { requireUser } from "~/services/session.server" ;
910import {
@@ -58,20 +59,13 @@ export const action = async ({ request }: ActionFunctionArgs) => {
5859 }
5960
6061 const body = await request . json ( ) ;
61-
62- if (
63- typeof body !== "object" ||
64- body === null ||
65- Array . isArray ( body ) ||
66- typeof body . flags !== "object" ||
67- body . flags === null ||
68- Array . isArray ( body . flags )
69- ) {
62+ const payloadSchema = z . object ( { flags : z . record ( z . unknown ( ) ) } ) ;
63+ const parsed = payloadSchema . safeParse ( body ) ;
64+ if ( ! parsed . success ) {
7065 return json ( { error : "Invalid payload" } , { status : 400 } ) ;
7166 }
7267
73- const newFlags = body . flags as Record < string , unknown > ;
74- const validationResult = validatePartialFeatureFlags ( newFlags ) ;
68+ const validationResult = validatePartialFeatureFlags ( parsed . data . flags ) ;
7569 if ( ! validationResult . success ) {
7670 return json (
7771 { error : "Invalid feature flags" , details : validationResult . error . issues } ,
You can’t perform that action at this time.
0 commit comments