T
TanStack7mo ago
wise-white

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?
}
})
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
1 Reply
extended-salmon
extended-salmon7mo ago
can you provide a complete minimal example by forking on of the existing examples on stackblitz and mocking out supabase?

Did you find this page helpful?