How to forward headers in request
Unanswered
Western thatching ant posted this in #help-forum
Western thatching antOP
import { config } from "./config";
import { getAccessLevel } from "./functions";
import Middleware from "./middleware";
import { headers } from "next/headers";
export const getAccessLevel = async (
headers: HeadersInit | undefined
) => {
try {
const response = await fetch(LINK, {
method: "GET",
headers: headers,
credentials: "include",
});
const data = await response.json();
return {
data: data.allAccessLevels.Items,
error: null,
};
} catch (error: any) {
console.log("Error Gettind Importer: ", error.message);
return {
data: {},
error: error.message,
};
}
};
const Page = async () => {
const { data, error } = await getAccessLevel(headers());
if (error) {
return <p>Error {error}</p>;
}
return <Middleware config={config} data={data} />;
};
export default Page;Getting errors forwarding the headers like that. How to do it ?
3 Replies
Western thatching antOP
does nobody know the solution for this trivial task ?
@Western thatching ant
import { config } from "./config";
import { getAccessLevel } from "./functions";
import Middleware from "./middleware";
import { headers } from "next/headers";
export const getAccessLevel = async (
headers: HeadersInit | undefined
) => {
try {
const response = await fetch(LINK, {
method: "GET",
headers: headers,
credentials: "include",
});
const data = await response.json();
return {
data: data.allAccessLevels.Items,
error: null,
};
} catch (error: any) {
console.log("Error Gettind Importer: ", error.message);
return {
data: {},
error: error.message,
};
}
};
const Page = async () => {
const { data, error } = await getAccessLevel(headers());
if (error) {
return <p>Error {error}</p>;
}
return <Middleware config={config} data={data} />;
};
export default Page;
Getting errors forwarding the headers like that. How to do it ?
what errors are you receiving? also, you don't need to use
credentials: 'include' in the request because the server doesn't hold any cookies, everything should be forwarded through the headersWestern thatching antOP
I ended up only forwarding the cookie from the header, but I wanted to forward all the header