BinarySenseiii
BinarySenseiii
TTCTheo's Typesafe Cult
Created by BinarySenseiii on 4/19/2024 in #questions
Conditional Validation in Form Schema Using Zod?
Hey everyone, I'm currently working on a validation schema for a form in my project, and I'm looking for some guidance on how to implement conditional validation. Here's a simplified version of what I have
export const createSchema = z.object({
method: z.enum(['fixed', 'timed', 'bids']),
price: z.string().optional().or(z.literal('')).transform(value => (value ? String(value) : '')),
title: z.string().min(1, {message: 'Please Enter Title'}),
file: z.instanceof(File, {message: 'Please Select File'}),
preview: z.instanceof(File, {message: 'Please Select Preview'}).nullable(),
})
export const createSchema = z.object({
method: z.enum(['fixed', 'timed', 'bids']),
price: z.string().optional().or(z.literal('')).transform(value => (value ? String(value) : '')),
title: z.string().min(1, {message: 'Please Enter Title'}),
file: z.instanceof(File, {message: 'Please Select File'}),
preview: z.instanceof(File, {message: 'Please Select Preview'}).nullable(),
})
In this schema, I have a method field which can take values 'fixed', 'timed', or 'bids'. What I'm trying to achieve is to make the price field required only when the method is set to 'fixed', otherwise, it should be optional. Could someone please guide me on how to add this conditional validation effectively using zod ? Thanks in advance for your help! 🙏
1 replies
TTCTheo's Typesafe Cult
Created by BinarySenseiii on 5/25/2023 in #questions
how to fix next auth ts error?
5 replies
TTCTheo's Typesafe Cult
Created by BinarySenseiii on 5/25/2023 in #questions
Build warnings?
2 replies
TTCTheo's Typesafe Cult
Created by BinarySenseiii on 5/19/2023 in #questions
Integrating Google OAuth with NextAuth.js: how to get Client and Token from google login
I would like to integrate Google OAuth with NextAuth.js and have an endpoint at /api/signin/google-oauth. To successfully authenticate a user, I need to provide the following data in the request body: "email": "[johndoe@example.com] " "entry_event_id": "string" (I already have this value) "google_client_id": "string" "google_token_id": "string" I'm unsure how to obtain the necessary "google_client_id" and "google_token_id" from Google. Could you please guide me on how to acquire these credentials? Additionally, once I have them, which approach is recommended for posting this data to the API from the client-side: using React Query or NextAuth.js callbacks? I'm new to Next.js, and any assistance would be greatly appreciated.
9 replies