#Fetching from server component
25 messages · Page 1 of 1 (latest)
I guess you cant use relative url for fetch in nodejs environment
If it helps, it’s my local api (in dev), I tried http://localhost:3000/api/servers but same thing
this should work! i think so try again
and then show ss of error
full
TypeError: Failed to parse URL from /api/servers
at Object.fetch (/Users/charlie/Documents/Development/Projects/polls.net/node_modules/next/dist/compiled/undici/index.js:1:26684)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async getServers (webpack-internal:///(sc_server)/./app/(app)/servers/page.tsx:11:17)
at async Page (webpack-internal:///(sc_server)/./app/(app)/servers/page.tsx:19:19) {
digest: '3770537177'
It needs the full url, since the fetch happens on the server, it doesnt know what the full url is
Can you provide the error when using the full url? because the above error is just with /api/servers
Ah I see, I didn't know, but weirdly session is null even though I'm signed in..
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const {name} = req.body;
const session = await getSession({ req });
console.log({ session })
u cant use getsession on api route
or usesession
you have to use Unstable_getsession maybe that name
idk specific
ahhh the one where i need to pass authoptions?
I replaced it with
const session = await unstable_getServerSession(req, res, authOptions);
but same thing, null
this should work i think so
becuse i use same
its null for some reason