diff --git a/app/[locale]/(back-nav)/ticketing/[eventId]/page.tsx b/app/[locale]/(back-nav)/ticketing/[eventId]/page.tsx index e7b677f..7a0cbc7 100644 --- a/app/[locale]/(back-nav)/ticketing/[eventId]/page.tsx +++ b/app/[locale]/(back-nav)/ticketing/[eventId]/page.tsx @@ -10,7 +10,8 @@ import { } from '@/components/ui/accordion'; import GlobalError, { GlobalErrorProps } from '@/app/global-error'; import { get, getImage } from '@/api'; -import { API_ROUTES } from '@/constants'; +import { API_ROUTES, API_URL, COOKIE_KEYS } from '@/constants'; +import { cookies } from 'next/headers'; type Term = { index: string; @@ -48,11 +49,39 @@ export default async function Page({ params: { eventId: string }; }) { try { + const atk = cookies().get(COOKIE_KEYS.accessToken)?.value; // const { key, image } = await getCaptchaImage(); - const { key } = await get<{ key: string }>(API_ROUTES.ticket.captcha.key, { - withCredentials: true, - }); - const image = await getImage(API_ROUTES.ticket.captcha.image(key)); + const data1 = await fetch(`${API_URL}${API_ROUTES.ticket.captcha.key}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${atk}`, + }, + }).then((res) => res.json()); + + const key = data1.key; + + const response = await fetch( + `${API_URL}${API_ROUTES.ticket.captcha.image(key)}`, + { + method: 'GET', + credentials: 'include', + headers: { + 'Content-Type': 'image/png', + Authorization: `Bearer ${atk}`, + }, + } + ); + + const arrBuf = await response.arrayBuffer(); + const text = String.fromCharCode.apply(null, new Uint8Array(arrBuf) as any); + + const image = 'data:image/jpeg;base64,' + btoa(text); + + // const { key } = await get<{ key: string }>(API_ROUTES.ticket.captcha.key, { + // withCredentials: true, + // }); + // const image = await getImage(API_ROUTES.ticket.captcha.image(key)); return (
diff --git a/hooks/useAuth.ts b/hooks/useAuth.ts index 46ddfb4..36e9480 100644 --- a/hooks/useAuth.ts +++ b/hooks/useAuth.ts @@ -56,7 +56,11 @@ export default function useAuth() { 'Content-Type': 'application/json', }, body: JSON.stringify(req), - }).then((res) => res.json()); + }) + .then((res) => res.json()) + .catch((e) => { + throw e; + }); if (!res.accessToken || !res.refreshToken) throw new Error('토큰이 없습니다.');