fix: return baseUrls if no uid is given to language switcher query
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { baseUrls } from "@/constants/routes/baseUrls"
|
||||
import { batchRequest } from "@/lib/graphql/batchRequest"
|
||||
import {
|
||||
GetDaDeEnUrlsAccountPage,
|
||||
@@ -13,7 +14,7 @@ import {
|
||||
GetFiNoSvUrlsLoyaltyPage,
|
||||
} from "@/lib/graphql/Query/LoyaltyPage.graphql"
|
||||
import { internalServerError } from "@/server/errors/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
import { publicProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
|
||||
@@ -91,12 +92,14 @@ async function getLanguageSwitcher(options: LanguageSwitcherVariables) {
|
||||
}
|
||||
|
||||
export const languageSwitcherQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
get: publicProcedure.query(async ({ ctx }) => {
|
||||
if (!ctx.uid || !ctx.lang) {
|
||||
return { lang: ctx.lang, urls: baseUrls }
|
||||
}
|
||||
const res = await getLanguageSwitcher({
|
||||
contentType: ctx.contentType!,
|
||||
uid: ctx.uid,
|
||||
})
|
||||
|
||||
const urls = Object.keys(res.data).reduce<LanguageSwitcherData>(
|
||||
(acc, key) => {
|
||||
const item = res.data[key as Lang]?.items[0]
|
||||
|
||||
Reference in New Issue
Block a user