-
Notifications
You must be signed in to change notification settings - Fork 0
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
회원가입 및 로그인 기능 수정 #99
Changes from 23 commits
8a67d1f
4501dd1
c2f09b0
b704ab2
7bd7cc1
a0da4f8
b21f95a
42ac17e
772675f
db6ab06
2b12233
e0599c2
503a20c
f1888fb
5bab953
c0f6dff
02babe2
151e15e
083a9f2
c282038
4d2b5d1
d5cacaa
2d2613c
975bd5b
959e9cc
13ba737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,6 @@ export const getKakaoCallback = async ( | |
code, | ||
}, | ||
}); | ||
console.log(response.data); | ||
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 = { | ||
|
@@ -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.SNITTO : RouterPath.GUARD; | ||
window.location.href = path; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 페이지 이동을 navigate와 window.location.href로 다르게 사용한 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. router 설정을 잘못한건지, 이유는 모르겠지만 navigate 를 사용하니까 /redirect/~~ 로 이동하더라구요. 근데 다시 하니까 정상적으로 되는것 같습니다.. |
||
} | ||
}, [data, navigate]); | ||
}, [data, navigate, setEmail]); | ||
|
||
return ( | ||
<Flex | ||
|
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'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -20,6 +22,8 @@ const RegisterPage = () => { | |
// 회원가입 처리 | ||
const mutation = useRegister(); | ||
|
||
const { email } = useAuth(); | ||
|
||
const handleUserType = (id: string) => { | ||
setUserType(id); | ||
}; | ||
|
@@ -31,7 +35,7 @@ const RegisterPage = () => { | |
const requestData = { | ||
name: data.name, | ||
phoneNumber: parsePhoneNumber(data.phoneNumber), | ||
email: '[email protected]', // 임시 (카카오 로그인 후 넘겨받기) | ||
email: email || '', | ||
isSinitto, | ||
}; | ||
console.log(requestData); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const GuardMainPage = () => { | ||
return <div>GuardMainPage</div>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { GuardMainPage } from './GuardMainPage'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const SinittoMainPage = () => { | ||
return <div>SinittoMainPage</div>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SinittoMainPage } from './SinittoMainPage'; |
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; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useAuth } from './Auth'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './auth'; | ||
export * from './senior-info'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기는 일부러 카카오 로그인 이후에 들어온 데이터 확인하려고 넣으신건가욤?