diff --git a/apps/web/api/ius/query.ts b/apps/web/api/ius/query.ts index 14315bb..0f2baa4 100644 --- a/apps/web/api/ius/query.ts +++ b/apps/web/api/ius/query.ts @@ -7,42 +7,46 @@ import wretch from 'wretch'; const urls = getUrls(); const api = wretch(urls.URL_IUS).options({ cache: 'no-store' }).errorType('json'); -type Input = { pageUrlParams: PageUrlParams; payload?: unknown }; +type Input = { cookie?: string; pageUrlParams: PageUrlParams; payload?: unknown }; -export async function getData({ pageUrlParams }: Input) { +export async function getData({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '', }); return api + .headers({ cookie }) .get(url) .res((cb) => cb.json()) .then((res) => res); } -export async function getMetaData({ pageUrlParams }: Input) { +export async function getMetaData({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '/meta' }); return api + .headers({ cookie }) .get(url) .res((res) => res.json()) .then((res) => res); } -export async function getConfig({ pageUrlParams }: Input) { +export async function getConfig({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '/config' }); return api + .headers({ cookie }) .get(url) .res((res) => res.json()) .then((res) => res); } -export async function getConditions({ pageUrlParams }: Input) { +export async function getConditions({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '/conditions' }); return api + .headers({ cookie }) .get(url) .res((res) => res.text()) .then((res) => res); @@ -68,19 +72,21 @@ export async function retract({ pageUrlParams, payload }: Input) { .catch((error: WretchError) => error.json as t.HttpValidationError | t.HttpError); } -export async function getDocumentTypes({ pageUrlParams }: Input) { +export async function getDocumentTypes({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '/documenttypes' }); return api + .headers({ cookie }) .get(url) .res((res) => res.json()) .then((res) => res); } -export async function getDocuments({ pageUrlParams }: Input) { +export async function getDocuments({ pageUrlParams, cookie = '' }: Input) { const url = createUrl({ ...pageUrlParams, route: '/documents' }); return api + .headers({ cookie }) .get(url) .res((res) => res.json()) .then((res) => res); diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 9dd1407..03951d2 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -6,6 +6,7 @@ import type { PageProps } from '@/types/page'; import { withError } from '@/utils/error'; import { getPageUrlParams } from '@/utils/url'; import type { Metadata } from 'next'; +import { headers } from 'next/headers'; export async function generateMetadata(pageProps: PageProps): Promise { const pageUrlParams = getPageUrlParams(pageProps); @@ -27,12 +28,15 @@ export default async function Page(pageProps: PageProps) { render: async () => { const pageUrlParams = getPageUrlParams(pageProps); + const headersList = headers(); + const cookie = headersList.get('cookie') ?? ''; + return Promise.all([ - apiIUS.getData({ pageUrlParams }), - apiIUS.getMetaData({ pageUrlParams }), - apiIUS.getConfig({ pageUrlParams }), - apiIUS.getDocumentTypes({ pageUrlParams }), - apiIUS.getDocuments({ pageUrlParams }), + apiIUS.getData({ cookie, pageUrlParams }), + apiIUS.getMetaData({ cookie, pageUrlParams }), + apiIUS.getConfig({ cookie, pageUrlParams }), + apiIUS.getDocumentTypes({ cookie, pageUrlParams }), + apiIUS.getDocuments({ cookie, pageUrlParams }), ]).then(([data, metaData, { title }, documentTypes, documents]) => { const combinedDocuments = combineDocuments({ documentTypes, documents }); const props: FormComponentProps = {