Skip to content
Discussion options

You must be logged in to vote

Answered on Discord as well, I think you're not supposed to use this in the client.
It uses cookies to manage the session so it needs to be called server-side.

Here's how I do it in my app:

import { createServerFn } from "@tanstack/react-start";
import { useAppSession } from "../session";

export const fetchSession = createServerFn({ method: "GET" }).handler(
    async () => {
        // We need to auth on the server so we have access to secure cookies
        const session = await useAppSession();

        return session.data;
    },
);

Then I use it in my __root beforeLoad to add it to the global context

export const Route = createRootRouteWithContext<AppContext>()({
    beforeLoad: async 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ujjwalsinghbasnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants