Skip to content

Commit

Permalink
aewf
Browse files Browse the repository at this point in the history
  • Loading branch information
ho991217 committed Apr 4, 2024
1 parent da34041 commit e261ac3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
39 changes: 34 additions & 5 deletions app/[locale]/(back-nav)/ticketing/[eventId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<div className='flex flex-col gap-4 mb-20 px-5'>
Expand Down
6 changes: 5 additions & 1 deletion hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('토큰이 없습니다.');
Expand Down

0 comments on commit e261ac3

Please sign in to comment.