Skip to content

Instantly share code, notes, and snippets.

@austinwoon
Created April 12, 2024 03:23
Show Gist options
  • Save austinwoon/4e7291ea3bf114539993a84f7beb13df to your computer and use it in GitHub Desktop.
Save austinwoon/4e7291ea3bf114539993a84f7beb13df to your computer and use it in GitHub Desktop.
Use iron session with create-t3-app
export const trpc = createTRPCNext({
config({ ctx }) {
return {
...
/**
* @link https://trpc.io/docs/links
*/
links: [
...,
httpLink({
/*
* Set custom request headers on every request from tRPC
* @link https://trpc.io/docs/ssr
*/
headers() {
if (ctx?.req) {
// To use SSR properly, you need to forward the client's headers to the server
// This is so you can pass through things like cookies when we're server-side rendering
// If you're using Node 18, omit the "connection" header
const { connection: _connection, ...headers } = ctx.req.headers
return {
...headers,
// Optional: inform server that it's an SSR request
'x-ssr': '1',
}
}
},
}),
],
}
},
})
@volfadar
Copy link

i also use create-t3-app, but there isn't any createTRPCNext initialization from the default create-t3-app setup. where i must put this file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment