fynn
fynn3mo ago

hono, next.js ssr & better-auth cookies

hey guys, I am currently trying to use Better Auth with tRPC server side with a hono backend. In my backend, I am checking for the session like this: const session = await auth.api.getSession({ headers: c.req.raw.headers }); in my trpc batchLink, I just tried to put headers like this:
async headers() {
const h = await nextHeaders();

return Object.fromEntries(header.entries());
},
async headers() {
const h = await nextHeaders();

return Object.fromEntries(header.entries());
},
with that, I am still UNAUTHORIZED; even if I am authorized on the client. does anyone know what I could do there? seems like it wont accept the headers?
1 Reply
Mokacchi
Mokacchi2d ago
I just got it to work by using
async headers() {
const cookieStore = await cookies();
return {
cookie: cookieStore.toString(),
[...other headers]
};
},
async headers() {
const cookieStore = await cookies();
return {
cookie: cookieStore.toString(),
[...other headers]
};
},

Did you find this page helpful?