TanStackT
TanStack11mo ago
1 reply
verbal-lime

Passing context from beforeLoad to loader

Hello all,

I am having trouble with passing extra context parameters down from
beforeLoad
to my loader function. See the code snippet below:

export const Route = createFileRoute('/_authenticated')({
  beforeLoad: ({context}) => {
    const session = context.queryClient.getQueryData<Session | null>(AUTH_SESSION_KEY);

    if (!session) {
        throw redirect({ to: '/' });
    }

    return {
        session,
    };
  }

  loader: async ({context}) => {
    // Use context.session.access_token for further operations
    // But context.session does not exist here. How?
  }
}) 


When I navigate one more time in my app, context.session is available. Does anyone know how?

Some more information: I am using Supabase Authentication and these are my authenticated routes. In the loader, I need to do a call to my own backend to get information on the user by using the
access_token
Was this page helpful?