[Error] Orval Generation apiClient skip server side code #2702
talha-newcortex
started this conversation in
General
Replies: 1 comment
-
|
the issue is orval runs at build time in node environment where next/headers is not available (its only available in server components at runtime). few options to fix this:
client mutator: // client-mutator.ts
export const getToken = () => {
return {
accessToken: Cookies.get("access_token"),
refreshToken: Cookies.get("refresh_token"),
};
};then use only the client mutator for orval generation.
export const getToken = async () => {
if (typeof window !== "undefined") {
return {
accessToken: Cookies.get("access_token"),
refreshToken: Cookies.get("refresh_token"),
};
}
try {
const { cookies } = await import("next/headers");
const cookieStore = await cookies();
return {
accessToken: cookieStore.get("access_token")?.value,
refreshToken: cookieStore.get("refresh_token")?.value,
};
} catch {
// orval build time - return empty tokens
return { accessToken: undefined, refreshToken: undefined };
}
};
// orval.config.js
mutator: {
path: "./src/api/client-only-mutator.ts",
name: "customInstance"
}
const isOrvalBuild = process.env.ORVAL_BUILD === "true";
export const getToken = async () => {
if (isOrvalBuild) {
return { accessToken: undefined, refreshToken: undefined };
}
// rest of your code
};then run: ORVAL_BUILD=true npx orval |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How can i disable server side code in orval mutator (api client)
I have login in my api-client for the serverside code, but I can't generate orval until i disable that line
The function being called is this
I have to disable the server side code in order to run the orval.
Full Code:
Error:
Beta Was this translation helpful? Give feedback.
All reactions