Skip to content

Commit 01c8e5d

Browse files
committed
[feat] 로그인 시 전페이지로 이동하도록 로직 추가 / 모달 store 추가
1 parent a11a2dd commit 01c8e5d

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

src/app/login/SocialLogin.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import Google from '@/shared/assets/icons/google.svg';
66
import tw from '@/shared/utills/tw';
77
import Welcome from './Welcome';
88
import { useState } from 'react';
9+
import { useAuthStore } from '@/shared/@store/auth';
910

1011
function SocialLogin() {
1112
const [isModalOpen, setIsModalOpen] = useState(false);
13+
const { user } = useAuthStore();
1214

1315
const socialButtons = [
1416
{
@@ -33,8 +35,10 @@ function SocialLogin() {
3335

3436
// TODO: 백엔드 연동 로직 구현 필요
3537
const handleLogin = (id: string) => {
36-
console.log(id);
37-
setIsModalOpen(true);
38+
const preLoginPath = sessionStorage.getItem('preLoginPath');
39+
console.log('경로, id', preLoginPath, id);
40+
41+
// useAuthStore.getState().loginWithProvider(id as 'naver' | 'kakao' | 'google');
3842
};
3943

4044
return (
@@ -54,7 +58,11 @@ function SocialLogin() {
5458
</div>
5559

5660
{/* 웰컴 모달 (임시) */}
57-
<Welcome open={isModalOpen} onClose={() => setIsModalOpen(false)} />
61+
<Welcome
62+
open={isModalOpen}
63+
onClose={() => setIsModalOpen(false)}
64+
nickname={user?.nickname || '게스트'}
65+
/>
5866
</>
5967
);
6068
}

src/app/login/Welcome.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import { useRouter } from 'next/navigation';
1010
interface Props {
1111
open: boolean;
1212
onClose: () => void;
13+
nickname: string;
1314
}
1415

15-
function Welcome({ open, onClose }: Props) {
16+
function Welcome({ open, onClose, nickname }: Props) {
1617
const router = useRouter();
1718

1819
return (
1920
<ModalLayout
2021
open={open}
2122
onClose={onClose}
22-
title="환영합니다!"
23+
title={`환영합니다, ${nickname}님!`}
2324
description="바텐더 쑤리가 안내해드릴게요"
2425
buttons={
2526
<>

src/app/oauth/success/page.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
import { useRouter } from 'next/navigation';
5+
import { useAuthStore } from '@/shared/@store/auth';
6+
import Spinner from '@/shared/components/spinner/Spinner';
7+
8+
function Page() {
9+
const router = useRouter();
10+
const { user } = useAuthStore();
11+
12+
useEffect(() => {
13+
if (user) {
14+
const prevPath = sessionStorage.getItem('preLoginPath') || '/';
15+
router.push(prevPath);
16+
sessionStorage.removeItem('preLoginPath');
17+
}
18+
}, [user, router]);
19+
return (
20+
<div className="page-layout max-w-824 flex-center">
21+
<Spinner />
22+
</div>
23+
);
24+
}
25+
export default Page;

src/shared/@store/modal.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { create } from 'zustand';
2+
3+
interface ModalState {
4+
welcomeOpen: boolean;
5+
openModal: (modal: keyof ModalState) => void;
6+
closeModal: (modal: keyof ModalState) => void;
7+
}
8+
9+
export const useModalStore = create<ModalState>((set) => ({
10+
welcomeOpen: false,
11+
12+
openModal: (modal) => set({ [modal]: true }),
13+
closeModal: (modal) => set({ [modal]: false }),
14+
}));

src/shared/components/header/HamburgerMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function HamburgerMenu() {
1414
<>
1515
<button
1616
type="button"
17-
className="sm:hidden block stroke-white hover:stroke-white/80 w-[63px]"
17+
className="sm:hidden block stroke-white hover:stroke-white/80"
1818
onClick={(e) => handleClick(e)}
1919
aria-label="메뉴 열기"
2020
aria-expanded={isClicked}

0 commit comments

Comments
 (0)