Skip to content

Commit

Permalink
Merge pull request #198 from Nexters/develop
Browse files Browse the repository at this point in the history
fix: 공연 상세 > 모바일에서 헤더 높이값 변경
  • Loading branch information
alstn2468 authored Sep 27, 2024
2 parents 2645353 + d50dcfd commit 5e44123
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
21 changes: 21 additions & 0 deletions apps/admin/src/atoms/useAuthAtom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LOCAL_STORAGE } from '@boolti/api';
import { atom, useAtom } from 'jotai';
import { useEffect } from 'react';

const storageMethod = {
getItem: (key: string, initialValue: string | null) => {
Expand Down Expand Up @@ -39,6 +40,26 @@ export const useAuthAtom = () => {

const isLogin = () => !!accessToken && !!refreshToken;

useEffect(() => {
const handler = (e: StorageEvent) => {
switch (e.key) {
case LOCAL_STORAGE.ACCESS_TOKEN: {
setAccessToken(e.newValue);
return;
}
case LOCAL_STORAGE.REFRESH_TOKEN: {
setRefreshToken(e.newValue);
return;
}
}
};
window.addEventListener('storage', handler);

return () => {
window.removeEventListener('storage', handler);
};
}, [setAccessToken, setRefreshToken]);

return {
setToken,
removeToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ const ShowNameWrapper = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
height: 80px;
height: 48px;
${mq_lg} {
height: 80px;
}
`;

const ShowName = styled.h2<ShowNameProps>`
Expand Down
40 changes: 20 additions & 20 deletions packages/api/src/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Options, ResponsePromise } from 'ky';
import ky from 'ky';
import ky, { HTTPError } from 'ky';

import BooltiHTTPError, { isBooltiHTTPError } from './BooltiHTTPError';
import { isBooltiHTTPError } from './BooltiHTTPError';
import { LOCAL_STORAGE } from './constants';

const API_URL = import.meta.env.VITE_BASE_API_URL;
Expand All @@ -24,7 +24,6 @@ const postRefreshToken = async () => {
},
},
);

return await response.json<PostRefreshTokenResponse>();
}
};
Expand Down Expand Up @@ -55,7 +54,6 @@ export const instance = ky.create({
if (!response.ok && response.status === 401 && !request.url.includes('logout')) {
try {
const { accessToken, refreshToken } = (await postRefreshToken()) ?? {};

if (accessToken && refreshToken) {
window.localStorage.setItem(LOCAL_STORAGE.ACCESS_TOKEN, accessToken);
window.localStorage.setItem(LOCAL_STORAGE.REFRESH_TOKEN, refreshToken);
Expand All @@ -64,24 +62,26 @@ export const instance = ky.create({

return ky(request, options);
}
} catch (error) {
throw new BooltiHTTPError(response, request, options);
}
}

if (!response.ok) {
const body = await response.json();

if (body) {
throw new BooltiHTTPError(response, request, options, {
errorTraceId: body.errorTraceId,
type: body.type,
detail: body.detail,
});
} catch (e) {
if (e instanceof HTTPError && e.response.url.includes('/login/refresh')) {
window.localStorage.removeItem(LOCAL_STORAGE.ACCESS_TOKEN);
window.localStorage.removeItem(LOCAL_STORAGE.REFRESH_TOKEN);
window.dispatchEvent(
new StorageEvent('storage', {
key: LOCAL_STORAGE.REFRESH_TOKEN,
newValue: undefined,
}),
);
window.dispatchEvent(
new StorageEvent('storage', {
key: LOCAL_STORAGE.ACCESS_TOKEN,
newValue: undefined,
}),
);
}
}

throw new BooltiHTTPError(response, request, options);
}
return response;
},
],
},
Expand Down

0 comments on commit 5e44123

Please sign in to comment.