Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

회원가입 및 로그인 기능 수정 #99

Merged
merged 26 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8a67d1f
Feat(auth): auth contextAPI 구현
Dobbymin Oct 21, 2024
4501dd1
Refactor(auth-provider): email만 상태관리 하도록 수정
Dobbymin Oct 21, 2024
c2f09b0
Feat(auth-provider): auth provider 적용
Dobbymin Oct 21, 2024
b704ab2
Feat(router): 시니또와 보호자 메인페이지 경로 상수화 구현
Dobbymin Oct 21, 2024
7bd7cc1
Feat(router): 시니또와 보호자 메인페이지 경로 추가
Dobbymin Oct 21, 2024
a0da4f8
Fix(router): redirect 페이지 Layout 제거
Dobbymin Oct 21, 2024
b21f95a
Refactor: 폴더구조 변경
Dobbymin Oct 21, 2024
42ac17e
Fix(redirect): token값에 페이지 이동 기능 구현 및 시니또, 보호자 페이지 이동 기능 구현
Dobbymin Oct 21, 2024
772675f
Fix(register): email 가져오기 기능 구현
Dobbymin Oct 21, 2024
db6ab06
Feat(guard-main): 보호자 메인페이지 추가
Dobbymin Oct 21, 2024
2b12233
Feat(sinitto-main): 시니또 메인페이지 추가
Dobbymin Oct 21, 2024
e0599c2
Refactor(senior-register): 시니어 등록 컴포넌트 분리
Diwoni Oct 20, 2024
503a20c
Refactor(senior-register): react-hook-form 으로 시니어 등록 컴포넌트 분리 및 리팩토링
Diwoni Oct 21, 2024
f1888fb
Feat(senior-register): 시니어 조회 API 연동
Diwoni Oct 21, 2024
5bab953
Feat(phone-number): 전화번호 포맷팅 hook 추가
Diwoni Oct 21, 2024
c0f6dff
Feat(senior-register): 시니어 추가 API 연동 및 전화번호 포맷팅 hook 수정
Diwoni Oct 21, 2024
02babe2
Feat(senior-register) : 시니어 정보 수정 및 삭제 API 연동(refetch 적용)
Diwoni Oct 21, 2024
151e15e
Style(senior-register): 페이지 레이아웃 조정
Diwoni Oct 21, 2024
083a9f2
Style(point-log): 포인트 내역 상태에 따라 포인트 스타일 변경
Diwoni Oct 21, 2024
c282038
Style(signup-page): 회원가입 시 전화번호 '-' 제거해서 API 요청
Diwoni Oct 21, 2024
4d2b5d1
Docs: 전화번호 포맷팅 관련 함수 파일 이동 (hooks -> utils)
Diwoni Oct 21, 2024
d5cacaa
Chore: 코드리뷰 반영
Diwoni Oct 21, 2024
2d2613c
Merge branch 'Weekly' into Feat/issue-#97
Dobbymin Oct 21, 2024
975bd5b
Fix(router): 오타 수정
Dobbymin Oct 21, 2024
959e9cc
Fix: 오류나는 부분 제거
Dobbymin Oct 21, 2024
13ba737
Feat(redirect): 페이지 변경 로직 수정
Dobbymin Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Routes } from './app/routes';
import { AllSeniorInfoProvider } from './shared';
import { queryClient } from './shared/api/instance';
import { AuthProvider } from './shared/provider/auth/Auth';
import { globalStyle } from './shared/theme/global';
import { ChakraProvider } from '@chakra-ui/react';
import { Global } from '@emotion/react';
Expand All @@ -11,8 +12,10 @@ const App = () => {
<ChakraProvider>
<QueryClientProvider client={queryClient}>
<AllSeniorInfoProvider>
<Global styles={globalStyle} />
<Routes />
<AuthProvider>
<Global styles={globalStyle} />
<Routes />
</AuthProvider>
</AllSeniorInfoProvider>
</QueryClientProvider>
</ChakraProvider>
Expand Down
21 changes: 20 additions & 1 deletion src/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SinittoGuideLinePage,
SinittoReviewPage,
HelloCallApplyPage,
GuardMainPage,
SinittoMainPage,
} from '@/pages';
import { Layout } from '@/shared/components';

Expand All @@ -38,14 +40,31 @@ export const router = createBrowserRouter([
},
{
path: RouterPath.REDIRECT,
element: <Layout title='안내' />,
children: [
{
index: true,
element: <RedirectPage />,
},
],
},
{
path: RouterPath.GUARD,
children: [
{
index: true,
element: <GuardMainPage />,
},
],
},
{
path: RouterPath.SINITTO,
children: [
{
index: true,
element: <SinittoMainPage />,
},
],
},
{
path: RouterPath.SINITTO_MYPAGE,
element: <Layout title='마이페이지' />,
Expand Down
2 changes: 2 additions & 0 deletions src/app/routes/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export const RouterPath = {
SIGNUP: '/signup',
REGISTER: '/register',
REDIRECT: '/redirection',
GUARD: '/guard',
GUARD_MYPAGE: `/guard/mypage`,
GUARD_GUIDELINE: `/guard/guideline`,
SINITTO: '/sinitto',
SINITTO_MYPAGE: `/sinitto/mypage`,
SERVICE_HISTORY: `/service-history`,
HELLO_CALL: `/hello-call`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export const getKakaoCallback = async (
code,
},
});
console.log(response.data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 일부러 카카오 로그인 이후에 들어온 데이터 확인하려고 넣으신건가욤?

return response.data;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import { useGetKakaoCallback } from '../../store/hooks';
import { RouterPath } from '@/app/routes/path';
import { useGetKakaoCallback } from '@/pages';
import { useAuth } from '@/shared';
import { Flex, Spinner, Text } from '@chakra-ui/react';

type Props = {
Expand All @@ -11,18 +13,28 @@ type Props = {
const RedirectSection = ({ code }: Props) => {
const navigate = useNavigate();

const { setEmail } = useAuth();

const { data } = useGetKakaoCallback(code);

useEffect(() => {
if (data) {
const accessToken = data.accessToken;
const refreshToken = data.refreshToken;

localStorage.setItem('accessToken', accessToken);
localStorage.setItem('refreshToken', refreshToken);

navigate('/');
setEmail(data.email);

if (!data.isMember) return navigate(data.redirectUrl);

if (accessToken) {
const path = data.isSinitto ? RouterPath.SINITTO : RouterPath.GUARD;
navigate(path);
}
}
}, [data, navigate]);
}, [data, navigate, setEmail]);

return (
<Flex
Expand Down
4 changes: 4 additions & 0 deletions src/pages/common/redirect/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default as RedirectPage } from './RedirectPage';

export * from './api';
export * from './hooks';
export * from './components';
6 changes: 5 additions & 1 deletion src/pages/common/register/RegisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { useRegister } from './store/hooks';
import { FormValues } from './types';
import { parsePhoneNumber } from '@/shared';
import { BasicButton } from '@/shared/components';
import { useAuth } from '@/shared/provider/auth/Auth';
import { Divider } from '@chakra-ui/react';
import styled from '@emotion/styled';

const RegisterPage = () => {
const [userType, setUserType] = useState('');

const {
register,
handleSubmit,
Expand All @@ -20,6 +22,8 @@ const RegisterPage = () => {
// 회원가입 처리
const mutation = useRegister();

const { email } = useAuth();

const handleUserType = (id: string) => {
setUserType(id);
};
Expand All @@ -31,7 +35,7 @@ const RegisterPage = () => {
const requestData = {
name: data.name,
phoneNumber: parsePhoneNumber(data.phoneNumber),
email: '[email protected]', // 임시 (카카오 로그인 후 넘겨받기)
email: email || '',
isSinitto,
};
console.log(requestData);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/guard/guard-main/GuardMainPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const GuardMainPage = () => {
return <div>GuardMainPage</div>;
};
1 change: 1 addition & 0 deletions src/pages/guard/guard-main/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { GuardMainPage } from './GuardMainPage';
1 change: 1 addition & 0 deletions src/pages/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './hello-call-apply';
export * from './register';
export * from './review';
export * from './service-history';
export * from './guard-main';
1 change: 1 addition & 0 deletions src/pages/sinitto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './hello-call-list';
export * from './hello-call-report';
export * from './hello-call-service';
export * from './mypage';
export * from './sinitto-main';
3 changes: 3 additions & 0 deletions src/pages/sinitto/sinitto-main/SinittoMainPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const SinittoMainPage = () => {
return <div>SinittoMainPage</div>;
};
1 change: 1 addition & 0 deletions src/pages/sinitto/sinitto-main/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SinittoMainPage } from './SinittoMainPage';
1 change: 0 additions & 1 deletion src/shared/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { useIntersectionObserver } from './useIntersectionObserver';
export type { UseIntersectionObserverProps } from './useIntersectionObserver';
export * from './point';
export * from './phone-number';
26 changes: 26 additions & 0 deletions src/shared/provider/auth/Auth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createContext, ReactNode, useContext, useState } from 'react';

type AuthInfo = {
email: string | null;
setEmail: (email: string) => void;
};

export const AuthContext = createContext<AuthInfo | undefined>(undefined);

export const AuthProvider = ({ children }: { children: ReactNode }) => {
const [email, setEmail] = useState<string | null>(null);

return (
<AuthContext.Provider value={{ email, setEmail }}>
{children}
</AuthContext.Provider>
);
};

export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth는 AuthProvider 내부에서 사용되어야 합니다.');
}
return context;
};
1 change: 1 addition & 0 deletions src/shared/provider/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useAuth } from './Auth';
1 change: 1 addition & 0 deletions src/shared/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './auth';
export * from './senior-info';