SmoothNanners
Tutorial for setting up tRPC with Next13 app dir?
I'm messing around with the new app dir. Here's what I'm doing so far.
I use server-side caller in server components (not passing hydrated state to React Query for now): https://trpc.io/docs/server/server-side-calls
For forms and client-side, instead of the Next.js server actions and foregoing progressive enhancement, I use the React Query integration (without the @trpc/next package) created in a client component that is wrapped around the root layout and react-hook-form as normal: https://trpc.io/docs/reactjs/setup
For trpc api route, I use the fetch adapter in app dir. Example:
3 replies
cookies, headers and authentication
There is the Lucia auth lib for SvelteKit: https://lucia-auth.vercel.app/
It sets some locals, it might be able to be passed to tRPC, but I haven't used it.
I have a repo for a custom auth with GitHub OAuth using endpoints as well and passes the session to the tRPC context, feel free to check it out https://github.com/austins/sveltekit-customauth
13 replies
cookies, headers and authentication
I tried to pass the SvelteKit cookies object into the context, but it didn't work since SvelteKit resolves the response separately. I was able to set cookies directly in the response (not using SvelteKit's cookies object) in responseMeta by checking the response and paths, but that's kinda messy. I recommend keeping the auth logic on a +page.server.js or +server.js endpoint. tRPC for everything else.
13 replies