Feature: Fastify Implementation (#274)

Co-authored-by: Aman Varshney <amanvarshney.work@gmail.com>
This commit is contained in:
Niloy
2025-05-22 17:32:32 +02:00
committed by GitHub
parent 17a7386071
commit b9dae19ce5
14 changed files with 243 additions and 2 deletions

View File

@@ -91,6 +91,29 @@ export async function createContext(opts: any) {
{{/if}}
}
{{else if (eq backend 'fastify')}}
import type { IncomingHttpHeaders } from "node:http";
{{#if auth}}
import { fromNodeHeaders } from "better-auth/node";
import { auth } from "./auth";
{{/if}}
export async function createContext(req: IncomingHttpHeaders) {
{{#if auth}}
const session = await auth.api.getSession({
headers: fromNodeHeaders(req),
});
return {
session,
};
{{else}}
// No auth configured
return {
session: null,
};
{{/if}}
}
{{else}}
export async function createContext() {
return {

View File

@@ -95,6 +95,27 @@ export async function createContext(opts: CreateExpressContextOptions) {
{{/if}}
}
{{else if (eq backend 'fastify')}}
import type { CreateFastifyContextOptions } from "@trpc/server/adapters/fastify";
{{#if auth}}
import { fromNodeHeaders } from "better-auth/node";
import { auth } from "./auth";
{{/if}}
export async function createContext({ req, res }: CreateFastifyContextOptions) {
{{#if auth}}
const session = await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
});
return { session };
{{else}}
// No auth configured
return {
session: null,
};
{{/if}}
}
{{else}}
export async function createContext() {
return {