Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing function as zValidator Middleware (accessing c) #584

Open
movahhedi opened this issue Jun 18, 2024 · 0 comments
Open

Passing function as zValidator Middleware (accessing c) #584

movahhedi opened this issue Jun 18, 2024 · 0 comments

Comments

@movahhedi
Copy link

I found the need to access the context object (c) in defining my zValidator.
Like this:

// ...
.post(
	"/login/otp",
	zValidator("json"
		z.object({
			otp: z.string().length(c.env.otpLength),
		}),
	),
// ...

I suggest supporting passing a function as the 2nd parameter of zValidator with a signature of somehting like (c: Context) => zValidatorType. Like this:

// ...
.post(
	"/login/otp",
	zValidator("json"
+		(c) => 
		z.object({
			otp: z.string().length(c.env.otpLength),
		}),
	),
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant