mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Feature: Fastify Implementation ⚡ (#274)
Co-authored-by: Aman Varshney <amanvarshney.work@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user