Client Response

I have a problem where what my API returns is not what the TS types say it is: For example what I actually receive when logging res is simply an object that looks like this {email, message}. But there is no ok, json() that my IDE says there should be. This is the route:
const ResponeSchema = z.object({
message: z.string(),
email: z.string().email(),
});
export const secret = new OpenAPIHono<{
Variables: ContextVariables;
}>().openapi(
createRoute({
method: "get",
path: "/api/secret",
tags: ["Secret"],
summary: "Shhh...",
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: ResponeSchema,
},
},
},
},
}),
(c) => {
const user = c.get("user")!;
return c.json(
{
message: "Secret Message",
email: user.email,
},
200
);
}
);
const ResponeSchema = z.object({
message: z.string(),
email: z.string().email(),
});
export const secret = new OpenAPIHono<{
Variables: ContextVariables;
}>().openapi(
createRoute({
method: "get",
path: "/api/secret",
tags: ["Secret"],
summary: "Shhh...",
responses: {
200: {
description: "Success",
content: {
"application/json": {
schema: ResponeSchema,
},
},
},
},
}),
(c) => {
const user = c.get("user")!;
return c.json(
{
message: "Secret Message",
email: user.email,
},
200
);
}
);
No description
5 Replies
Aditya Mathur
Aditya Mathur6d ago
Seems to be working fine on my end
No description
ForkMeDaddy
ForkMeDaddy6d ago
I am using ofetch as my fetch fn. could this be related?
export const client = hc<AppType>(getBaseUrl(), {
async fetch(input, requestInit, _, __) {
return $fetch(input instanceof URL ? input.toString() : input, {
...requestInit,
...(typeof window === "undefined"
? (await import("next/headers")).headers()
: {}),
});
},
});
export const client = hc<AppType>(getBaseUrl(), {
async fetch(input, requestInit, _, __) {
return $fetch(input instanceof URL ? input.toString() : input, {
...requestInit,
...(typeof window === "undefined"
? (await import("next/headers")).headers()
: {}),
});
},
});
ForkMeDaddy
ForkMeDaddy6d ago
ok when I change it to this it works: (use normal fetch)
No description
ForkMeDaddy
ForkMeDaddy6d ago
neat
Aditya Mathur
Aditya Mathur6d ago
So is this issue resolved for you?
Want results from more Discord servers?
Add your server