fix(LOY-206): add missing lang input to friends transactions query, handles both server and client side
This commit is contained in:
@@ -52,32 +52,33 @@ const baseProcedure = t.procedure.use(sentryMiddleware)
|
||||
|
||||
export const publicProcedure = baseProcedure
|
||||
|
||||
export const contentstackBaseProcedure = baseProcedure.use(
|
||||
async function (opts) {
|
||||
if (!opts.ctx.lang) {
|
||||
// When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers
|
||||
// We can then pass lang as an input in the request and set it to the context in the procedure
|
||||
export const languageProcedure = baseProcedure.use(async function (opts) {
|
||||
if (!opts.ctx.lang) {
|
||||
// When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers
|
||||
// We can then pass lang as an input in the request and set it to the context in the procedure
|
||||
|
||||
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,
|
||||
},
|
||||
})
|
||||
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: opts.ctx.lang,
|
||||
lang: parsedInput.data.lang,
|
||||
},
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return opts.next({
|
||||
ctx: {
|
||||
lang: opts.ctx.lang,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
export const contentstackBaseProcedure = languageProcedure
|
||||
|
||||
export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use(
|
||||
async function (opts) {
|
||||
if (!opts.ctx.uid) {
|
||||
@@ -207,5 +208,8 @@ export const contentStackBaseWithProtectedProcedure =
|
||||
export const safeProtectedServiceProcedure =
|
||||
safeProtectedProcedure.unstable_concat(serviceProcedure)
|
||||
|
||||
export const protectedServcieProcedure =
|
||||
export const protectedServiceProcedure =
|
||||
protectedProcedure.unstable_concat(serviceProcedure)
|
||||
|
||||
export const languageProtectedProcedure =
|
||||
protectedProcedure.unstable_concat(languageProcedure)
|
||||
|
||||
Reference in New Issue
Block a user