feat: improve structure and error handling

This commit is contained in:
Michael Zetterberg
2024-05-14 15:55:46 +02:00
parent 01587d7fd5
commit f5108d1a8e
104 changed files with 1505 additions and 1570 deletions
+18
View File
@@ -1,7 +1,15 @@
import { headers } from "next/headers"
import { Lang } from "@/constants/languages"
import { auth } from "@/auth"
type CreateContextOptions = {
auth: typeof auth
lang: Lang
pathname: string
uid?: string | null
url: string
}
/** Use this helper for:
@@ -11,6 +19,10 @@ type CreateContextOptions = {
export function createContextInner(opts: CreateContextOptions) {
return {
auth: opts.auth,
lang: opts.lang,
pathname: opts.pathname,
uid: opts.uid,
url: opts.url,
}
}
@@ -19,8 +31,14 @@ export function createContextInner(opts: CreateContextOptions) {
* @link https://trpc.io/docs/context
**/
export function createContext() {
const h = headers()
return createContextInner({
auth,
lang: h.get("x-lang") as Lang,
pathname: h.get("x-pathname")!,
uid: h.get("x-uid"),
url: h.get("x-url")!,
})
}