Secure your tRPC based on iron-session authentication.
The project structure is based on iron-session examples next.js-typescript
Changed the HTTP API part to tRPC without changing the project structure as much as possible.
Thanks to this, if you pour iron-session examples next.js-typescript here as it is, it will diff so you can easily see the changes.
that the
SSGpage in the example is meaningless because of theSSRoption oftRPC. 🙄
npm i
npm run devIf you are logged in through SSR , you may want to quickly display user information in the <Header /> .
To do this, you need to pass cookies to tRPC during SSR.
Please refer to src/utils/trpc.ts for the related code.
If you are familiar with iron-session, we will use the req.session to manipulate cookies.
tRPC must be passed as a Context to achieve this.
Please refer to src/server/context.ts for the related code.