apps/web: fix pass cookie to api request
This commit is contained in:
parent
4733f2bb61
commit
4d5ab7fd36
@ -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<t.ResponseGetData>((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<t.ResponseMetaData>((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<t.ResponseConfig>((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<t.ResponseConditions>((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<t.ResponseDocumentTypes>((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<t.ResponseDocuments>((res) => res.json())
|
||||
.then((res) => res);
|
||||
|
||||
@ -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<Metadata> {
|
||||
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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user