fix: refactor lang handling in contentstack base procedure
This commit is contained in:
+13
-2
@@ -4,6 +4,7 @@ import { env } from "@/env/server"
|
||||
|
||||
import { badRequestError, sessionExpiredError } from "./errors/trpc"
|
||||
import { transformer } from "./transformer"
|
||||
import { langInput } from "./utils"
|
||||
|
||||
import type { Meta } from "@/types/trpc/meta"
|
||||
import type { Context } from "./context"
|
||||
@@ -12,9 +13,19 @@ const t = initTRPC.context<Context>().meta<Meta>().create({ transformer })
|
||||
|
||||
export const { createCallerFactory, mergeRouters, router } = t
|
||||
export const publicProcedure = t.procedure
|
||||
export const contentstackBaseProcedure = t.procedure.use(function (opts) {
|
||||
export const contentstackBaseProcedure = t.procedure.use(async function (opts) {
|
||||
if (!opts.ctx.lang) {
|
||||
throw badRequestError("Missing Lang in tRPC context")
|
||||
const input = await opts.getRawInput()
|
||||
|
||||
const parsedInput = langInput.safeParse(input)
|
||||
if (!parsedInput.success) {
|
||||
throw badRequestError("Missing Lang in tRPC context")
|
||||
}
|
||||
return opts.next({
|
||||
ctx: {
|
||||
lang: parsedInput.data.lang,
|
||||
},
|
||||
})
|
||||
}
|
||||
return opts.next({
|
||||
ctx: {
|
||||
|
||||
Reference in New Issue
Block a user