feat: improve structure and error handling
This commit is contained in:
@@ -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")!,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user