How to currently access request headers?
I see some old suggestions linking to a page in server functions that no longer exists.
https://tanstack.com/start/latest/docs/framework/react/server-functions#accessing-the-request-context
SSR is causing issues with better-auth and i was attempting to create an isomorphic function that would correctly fetch the user's session like so:
2 Replies
xenial-black•3w ago
Here =>
import { createMiddleware, createServerFn } from "@tanstack/react-start";
import { auth } from "./auth";
export const authMiddleware = createMiddleware().server(
async ({ next, request }) => {
const session = await auth.api.getSession({
headers: request.headers,
});
return next({
context: { session },
});
}
);
export const getCurrentUserFn = createServerFn({ method: "GET" })
.middleware([authMiddleware])
.handler(async ({ context }) => context.session);
yammering-amber•2w ago
This worked for me: