Skip to content

Commit f34d416

Browse files
authored
[#659] 로그인 완료 후 이전 페이지로 돌아올 수 있는 기능 구현 (#661)
* feat: 로그인 Link 컴포넌트 추가 * fix: kakao login base url 상수파일에서 import하도록 수정
1 parent 351f4a2 commit f34d416

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

src/app/bookshelf/[bookshelfId]/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client';
22

33
import { useEffect } from 'react';
4-
import Link from 'next/link';
54
import { useInView } from 'react-intersection-observer';
65

76
import type { APIBookshelf } from '@/types/bookshelf';
@@ -12,7 +11,6 @@ import useMutateBookshelfLikeQuery from '@/queries/bookshelf/useMutateBookshelfL
1211
import { useMyProfileId } from '@/queries/user/useMyProfileQuery';
1312
import { checkAuthentication } from '@/utils/helpers';
1413
import { IconKakao } from '@public/icons';
15-
import { KAKAO_LOGIN_URL } from '@/constants';
1614

1715
import useToast from '@/components/common/Toast/useToast';
1816
import TopNavigation from '@/components/common/TopNavigation';
@@ -21,6 +19,7 @@ import Button from '@/components/common/Button';
2119
import LikeButton from '@/components/common/LikeButton';
2220
import BackButton from '@/components/common/BackButton';
2321
import ShareButton from '@/components/common/ShareButton';
22+
import LoginLink from '@/components/common/LoginLink';
2423

2524
export default function UserBookShelfPage({
2625
params: { bookshelfId },
@@ -163,14 +162,14 @@ const BookShelfLoginBox = ({
163162
<br />
164163
인사이트를 얻을 수 있어요.
165164
</p>
166-
<Link href={KAKAO_LOGIN_URL}>
165+
<LoginLink>
167166
<Button colorScheme="kakao" size="full">
168167
<div className="flex items-center justify-center gap-[1rem]">
169168
<IconKakao width={16} height={'auto'} />
170169
<span className="font-body1-regular">카카오 로그인</span>
171170
</div>
172171
</Button>
173-
</Link>
172+
</LoginLink>
174173
</div>
175174
);
176175
};

src/app/login/page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'use client';
2-
31
import Link from 'next/link';
42
import Image from 'next/image';
53

64
import { IconKakao } from '@public/icons';
7-
import { KAKAO_LOGIN_URL } from '@/constants';
85

96
import Button from '@/components/common/Button';
7+
import LoginLink from '@/components/common/LoginLink';
108

119
const LoginPage = () => {
1210
return (
@@ -30,14 +28,14 @@ const LoginPage = () => {
3028
</article>
3129

3230
<section className="absolute inset-x-[2rem] bottom-[calc(env(safe-area-inset-bottom)+2rem)] mx-auto flex max-w-[41rem] flex-col justify-center gap-[1rem]">
33-
<Link href={KAKAO_LOGIN_URL}>
31+
<LoginLink>
3432
<Button size="full" colorScheme="kakao">
3533
<div className="flex w-full items-center justify-center">
3634
<IconKakao className="absolute left-[2rem] w-[2.1rem]" />
3735
<p>카카오 로그인</p>
3836
</div>
3937
</Button>
40-
</Link>
38+
</LoginLink>
4139
<Link href="/bookarchive" className="flex justify-center">
4240
<Button
4341
size="small"

src/app/profile/me/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import userKeys from '@/queries/user/key';
1010
import { deleteAuthSession } from '@/server/session';
1111
import { deleteCookie } from '@/utils/cookie';
1212
import { checkAuthentication } from '@/utils/helpers';
13-
import { KAKAO_LOGIN_URL, SESSION_COOKIES_KEYS } from '@/constants';
13+
import { SESSION_COOKIES_KEYS } from '@/constants';
1414
import { IconArrowRight } from '@public/icons';
1515

1616
import SSRSafeSuspense from '@/components/common/SSRSafeSuspense';
@@ -20,6 +20,7 @@ import Button from '@/components/common/Button';
2020
import Loading from '@/components/common/Loading';
2121
import Menu from '@/components/common/Menu';
2222
import TopHeader from '@/components/common/TopHeader';
23+
import LoginLink from '@/components/common/LoginLink';
2324
import BookShelf from '@/components/bookShelf/BookShelf';
2425
import ProfileBookShelf from '@/components/profile/bookShelf/ProfileBookShelf';
2526
import ProfileGroup from '@/components/profile/group/ProfileGroup';
@@ -51,9 +52,9 @@ const MyProfileForUnAuth = () => {
5152
카카오로 3초만에 가입할 수 있어요.
5253
</p>
5354
</div>
54-
<Link href={KAKAO_LOGIN_URL}>
55+
<LoginLink>
5556
<IconArrowRight width="20px" />
56-
</Link>
57+
</LoginLink>
5758
</div>
5859
<div className="flex flex-col gap-[0.6rem]">
5960
<div className="flex items-center justify-between">
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import Link from 'next/link';
2-
3-
import { KAKAO_LOGIN_URL } from '@/constants';
4-
51
import BottomActionButton from '@/components/common/BottomActionButton';
2+
import LoginLink from '@/components/common/LoginLink';
63

74
const LoginBottomActionButton = () => (
8-
<Link href={KAKAO_LOGIN_URL}>
5+
<LoginLink>
96
<BottomActionButton>로그인 및 회원가입</BottomActionButton>
10-
</Link>
7+
</LoginLink>
118
);
129

1310
export default LoginBottomActionButton;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use client';
2+
3+
import type { ComponentPropsWithRef, PropsWithChildren } from 'react';
4+
import Link from 'next/link';
5+
import { usePathname } from 'next/navigation';
6+
7+
import { SEARCH_PARAMS_KEYS } from '@/constants/key';
8+
import { KAKAO_LOGIN_BASE_URL } from '@/constants/url';
9+
import { createQueryString } from '@/utils/url';
10+
11+
type LoginLinkProps = Omit<ComponentPropsWithRef<typeof Link>, 'href'>;
12+
13+
const LoginLink = ({
14+
children,
15+
replace = true,
16+
...props
17+
}: PropsWithChildren<LoginLinkProps>) => {
18+
const pathname = usePathname();
19+
const search = createQueryString({
20+
...(pathname && { [SEARCH_PARAMS_KEYS.REDIRECT_PATHNAME]: pathname }),
21+
});
22+
23+
return (
24+
<Link
25+
href={`${KAKAO_LOGIN_BASE_URL}${search}`}
26+
replace={replace}
27+
{...props}
28+
>
29+
{children}
30+
</Link>
31+
);
32+
};
33+
34+
export default LoginLink;

src/constants/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export const DATA_URL = {
33
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdjWL9+/X8ABysDDapsaG4AAAAASUVORK5CYII=', // data url for placeholder color (#AFAFAF)
44
};
55

6-
export const KAKAO_LOGIN_URL = `${process.env.NEXT_PUBLIC_API_URL}/oauth2/authorize/kakao?redirect_uri=${process.env.NEXT_PUBLIC_CLIENT_REDIRECT_URI}`;
6+
export const KAKAO_LOGIN_BASE_URL = `${process.env.NEXT_PUBLIC_API_URL}/oauth2/authorize/kakao?redirect_uri=${process.env.NEXT_PUBLIC_CLIENT_REDIRECT_URI}`;

0 commit comments

Comments
 (0)