TanStackT
TanStack5mo ago
5 replies
radical-lime

server side context?

I am trying to implement pocketbase auth and currently I do:
export const authenticate = createServerFn().handler(async () => {
    pb.authStore.loadFromCookie(getCookie(cookieName) || '');

    try {
        pb.authStore.isValid && (await pb.collection('users').authRefresh());
    } catch {
        pb.authStore.clear();
    }

    setCookie(cookieName, pb.authStore.exportToCookie());

    return { record: pb.authStore.record };
})

// _auth.tsx route
    beforeLoad: async ({ context }) => {
        const data = await authenticate();
        if (!data.record) throw redirect({ to: '/login' });
        return { ...context, record: data.record };
    },


the problem is pocketbase instace is created once during server startup, but I want to create a new instance for each request but I'm struggling to figure out how to do that in start.
Was this page helpful?