Skip to content

Commit

Permalink
Merge pull request #200 from SystemConsultantGroup/hotfix/jaewon-fix-…
Browse files Browse the repository at this point in the history
…initial-login-error

카카오 로그인 하고 처음으로 돌아온 직후 Loading 표시 지속되고 이름 표시 안 되는 문제 임시로 해결
  • Loading branch information
jaychang99 authored Feb 9, 2025
2 parents f58260e + 4493da2 commit 2998d51
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/utils/fetcher/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getServerSideToken } from "@/components/common/Auth";
import { REFRESH_TOKEN_NAME } from "@/constants/Auth";
import { JWT_COOKIE_NAME, REFRESH_TOKEN_NAME } from "@/constants/Auth";
import { CommonAxios } from "@/utils/CommonAxios";
import Cookies from "js-cookie";

export interface FetcherArgs {
url: string;
Expand All @@ -16,8 +17,7 @@ export interface FetcherArgs {
* @returns api 서버로부터 반환되는 데이터
*/
export async function fetcher({ url, query }: FetcherArgs) {
const { accessToken } = await getServerSideToken();

const { accessToken } = await getIsomorphicToken();
CommonAxios.defaults.headers.Authorization = `Bearer ${accessToken}`;
CommonAxios.defaults.withCredentials = true;

Expand All @@ -43,3 +43,17 @@ export async function ServerSideFetcher({ url, query }: FetcherArgs) {

return (await CommonAxios.get(url, config)).data;
}

const getIsomorphicToken = async () => {
if (typeof window !== "undefined") {
// 브라우저 환경
const accessToken = Cookies.get(JWT_COOKIE_NAME);
return { accessToken };
} else {
// 서버 환경
// getServerSideToken 내부의 next/headers 에서 가져오는 cookies 가
// 클라이언트 프로덕션 환경에서는 문제를 일으켜서 우선 임시로 이렇게 해결
const { accessToken } = await getServerSideToken();
return { accessToken };
}
};

0 comments on commit 2998d51

Please sign in to comment.