diff --git a/src/@types/auth.types.ts b/src/@types/auth.types.ts index c95769ab..68022c80 100644 --- a/src/@types/auth.types.ts +++ b/src/@types/auth.types.ts @@ -1,4 +1,4 @@ -export interface AuthRequest { +interface AuthRequest { email: string; password: string; name: string; @@ -9,7 +9,7 @@ export interface AuthRequest { survey: string; } -export interface LoginFormVlaue { +interface LoginFormVlaue { email: string; password: string; } diff --git a/src/api/auth.ts b/src/api/auth.ts index b9abe8cf..53f8ce9f 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -21,13 +21,13 @@ export const postSignup = async (authData: AuthRequest) => { }; // 로그인-이메일 -export const postEmailLogin = async (LoginData: LoginRequest) => { +export const postEmailLogin = async (LoginData: LoginFormVlaue) => { const res = await client.post(`auth/login`, LoginData); return res; }; // 로그인-카카오 -export const postKakaoLogin = async (LoginData: LoginRequest) => { +export const postKakaoLogin = async (LoginData: LoginFormVlaue) => { const res = await client.post(`auth/login/kakao`, LoginData); return res; }; diff --git a/src/components/user/useInputBox/UserEmailInputBox.tsx b/src/components/Auth/AuthInputBox/AuthEmailInputBox.tsx similarity index 96% rename from src/components/user/useInputBox/UserEmailInputBox.tsx rename to src/components/Auth/AuthInputBox/AuthEmailInputBox.tsx index d34cd1e3..d106be56 100644 --- a/src/components/user/useInputBox/UserEmailInputBox.tsx +++ b/src/components/Auth/AuthInputBox/AuthEmailInputBox.tsx @@ -1,7 +1,7 @@ import { CloseIcon } from '@components/common/icons/Icons'; import { useState } from 'react'; -const UserEmailInputBox = () => { +const AuthEmailInputBox = () => { const [inputValue, setInputValue] = useState(''); const [isEmailValidated, setIsEmailValidated] = useState(true); @@ -63,4 +63,4 @@ const UserEmailInputBox = () => { ); }; -export default UserEmailInputBox; +export default AuthEmailInputBox; diff --git a/src/components/user/useInputBox/UserInputBox.tsx b/src/components/Auth/AuthInputBox/AuthInputBox.tsx similarity index 94% rename from src/components/user/useInputBox/UserInputBox.tsx rename to src/components/Auth/AuthInputBox/AuthInputBox.tsx index a969e1b8..2880d0a8 100644 --- a/src/components/user/useInputBox/UserInputBox.tsx +++ b/src/components/Auth/AuthInputBox/AuthInputBox.tsx @@ -1,6 +1,5 @@ import { CloseIcon } from '@components/common/icons/Icons'; import { UseFormRegisterReturn, UseFormSetValue } from 'react-hook-form'; -import { LoginFormVlaue } from '@/@types/auth.types'; interface Props { label: string; @@ -16,7 +15,7 @@ interface Props { // children: React.ReactNode; } -const UserInputBox = ({ +const AuthInputBox = ({ label, id, type = 'text', @@ -68,4 +67,4 @@ const UserInputBox = ({ ); }; -export default UserInputBox; +export default AuthInputBox; diff --git a/src/components/user/useInputBox/UserPwInputBox.tsx b/src/components/Auth/AuthInputBox/AuthPwInputBox.tsx similarity index 98% rename from src/components/user/useInputBox/UserPwInputBox.tsx rename to src/components/Auth/AuthInputBox/AuthPwInputBox.tsx index 0abc5a80..f4c83b0d 100644 --- a/src/components/user/useInputBox/UserPwInputBox.tsx +++ b/src/components/Auth/AuthInputBox/AuthPwInputBox.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { CloseIcon } from '@components/common/icons/Icons'; import ValidifyCheck from './ValidifyCheck'; -const UserPwInputBox = () => { +const AuthPwInputBox = () => { const [inputPwValue, setInputPwValue] = useState(''); const onPwInputChange = (e: React.ChangeEvent) => { @@ -97,4 +97,4 @@ const UserPwInputBox = () => { ); }; -export default UserPwInputBox; +export default AuthPwInputBox; diff --git a/src/components/user/useInputBox/ValidifyCheck.tsx b/src/components/Auth/AuthInputBox/ValidifyCheck.tsx similarity index 94% rename from src/components/user/useInputBox/ValidifyCheck.tsx rename to src/components/Auth/AuthInputBox/ValidifyCheck.tsx index 08957916..eaf00fa8 100644 --- a/src/components/user/useInputBox/ValidifyCheck.tsx +++ b/src/components/Auth/AuthInputBox/ValidifyCheck.tsx @@ -1,5 +1,5 @@ import { CheckIcon } from '@components/common/icons/Icons'; -import validationList from '@utils/user/validationList'; +import validationList from '@utils/Auth/validationList'; import { useEffect, useState } from 'react'; interface Props { diff --git a/src/components/user/ErrorMessage.tsx b/src/components/Auth/ErrorMessage.tsx similarity index 100% rename from src/components/user/ErrorMessage.tsx rename to src/components/Auth/ErrorMessage.tsx diff --git a/src/components/Auth/KakaoLoginButton.tsx b/src/components/Auth/KakaoLoginButton.tsx new file mode 100644 index 00000000..8d871741 --- /dev/null +++ b/src/components/Auth/KakaoLoginButton.tsx @@ -0,0 +1,23 @@ +import { KakaoIcon } from '@components/common/icons/Icons'; + +const KakaoLoginButton = () => { + const VITE_KAKAO_LOGIN_TEST_API_KEY = import.meta.env + .VITE_KAKAO_LOGIN_TEST_API_KEY; + const REDIRECT_URI = `${window.location.href}/kakao`; + const KAKAO_LOGIN_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${VITE_KAKAO_LOGIN_TEST_API_KEY}&redirect_uri=${REDIRECT_URI}&response_type=code`; + + const onKakaoLoginClick = () => { + window.location.href = KAKAO_LOGIN_URL; + }; + + return ( + + ); +}; + +export default KakaoLoginButton; diff --git a/src/components/Auth/index.ts b/src/components/Auth/index.ts new file mode 100644 index 00000000..7969844f --- /dev/null +++ b/src/components/Auth/index.ts @@ -0,0 +1,13 @@ +import AuthInputBox from './AuthInputBox/AuthInputBox'; +import AuthEmailInputBox from './AuthInputBox/AuthEmailInputBox'; +import AuthPwInputBox from './AuthInputBox/AuthPwInputBox'; +import ErrorMessage from './ErrorMessage'; +import KakaoLoginButton from './KakaoLoginButton'; + +export { + AuthInputBox, + AuthEmailInputBox, + AuthPwInputBox, + ErrorMessage, + KakaoLoginButton, +}; diff --git a/src/components/user/index.ts b/src/components/user/index.ts deleted file mode 100644 index 844de37c..00000000 --- a/src/components/user/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import UserInputBox from './useInputBox/UserInputBox'; -import UserEmailInputBox from './useInputBox/UserEmailInputBox'; -import UserPwInputBox from './useInputBox/UserPwInputBox'; -import ErrorMessage from './ErrorMessage'; - -export { UserInputBox, UserEmailInputBox, UserPwInputBox, ErrorMessage }; diff --git a/src/pages/index.ts b/src/pages/index.ts index f281dab8..a92a70c4 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -1,4 +1,4 @@ import { Signup, SignupInfo } from './signup'; -import Login from './login/login.page'; +import { Login, LoginKakao } from './login'; -export { Signup, SignupInfo, Login }; +export { Signup, SignupInfo, Login, LoginKakao }; diff --git a/src/pages/login/index.ts b/src/pages/login/index.ts new file mode 100644 index 00000000..89b178eb --- /dev/null +++ b/src/pages/login/index.ts @@ -0,0 +1,4 @@ +import Login from './login.page'; +import LoginKakao from './loginKakao.page'; + +export { Login, LoginKakao }; diff --git a/src/pages/login/login.page.tsx b/src/pages/login/login.page.tsx index 6a7c45bb..644bb7b4 100644 --- a/src/pages/login/login.page.tsx +++ b/src/pages/login/login.page.tsx @@ -2,11 +2,10 @@ import { postEmailLogin } from '@api/auth'; import authCient from '@api/authClient'; import SubmitBtn from '@components/common/button/SubmitBtn'; import Back from '@components/common/back/Back'; -import { KakaoIcon, LogoIcon } from '@components/common/icons/Icons'; -import { ErrorMessage, UserInputBox } from '@components/user'; +import { LogoIcon } from '@components/common/icons/Icons'; +import { ErrorMessage, AuthInputBox, KakaoLoginButton } from '@components/Auth'; import { useNavigate } from 'react-router-dom'; import { SubmitHandler, useForm } from 'react-hook-form'; -import { LoginFormVlaue } from '@/@types/auth.types'; import { useState } from 'react'; import { AxiosError } from 'axios'; @@ -20,7 +19,6 @@ const Login = () => { formState: { errors }, } = useForm({ reValidateMode: 'onSubmit', - // 다른 옵션들... }); const [isLoginFailed, setIsLoginFailed] = useState(false); @@ -60,7 +58,7 @@ const Login = () => {
- { inputValue={watch('email')} setValue={setValue} /> - { {!errors.email && !errors.password && isLoginFailed && ( <> - 아이디(로그인 전용 아이디) 또는 비밀번호를 잘못 입력했습니다. + 이메일 또는 비밀번호를 잘못 입력했습니다. 입력하신 내용을 다시 확인해주세요. @@ -105,10 +103,7 @@ const Login = () => { 또는
- + 회원가입 diff --git a/src/pages/login/loginKakao.page.tsx b/src/pages/login/loginKakao.page.tsx new file mode 100644 index 00000000..78b84b79 --- /dev/null +++ b/src/pages/login/loginKakao.page.tsx @@ -0,0 +1,19 @@ +import { postKakaoLogin } from '@api/auth'; +import { useEffect } from 'react'; + +const LoginKakao = () => { + const code = new URL(window.location.href).searchParams.get('code'); + + useEffect(() => { + console.log(code); + try { + const res = postKakaoLogin(); + } catch (err) { + console.log('카카오 로그인 중 에러 발생'); + } + }, []); + + return
잠시만 기다려주세요
; +}; + +export default LoginKakao; diff --git a/src/pages/signup/signup.page.tsx b/src/pages/signup/signup.page.tsx index 9adca927..73423e16 100644 --- a/src/pages/signup/signup.page.tsx +++ b/src/pages/signup/signup.page.tsx @@ -1,4 +1,4 @@ -import { UserEmailInputBox, UserPwInputBox } from '@components/user'; +import { AuthEmailInputBox, AuthPwInputBox } from '@components/Auth'; import { useState } from 'react'; const Signup = () => { @@ -12,8 +12,8 @@ const Signup = () => { 회원가입을 해주세요 - - + + {/* TODO 서지수 | 모든 조건이 만족되어야지만 활성화되도록 수정 */}
diff --git a/src/router/authRouter.tsx b/src/router/authRouter.tsx index 520a7266..36598403 100644 --- a/src/router/authRouter.tsx +++ b/src/router/authRouter.tsx @@ -1,7 +1,7 @@ import { Routes, Route } from 'react-router-dom'; import MainLayout from './mainLayout'; import { Signup, SignupInfo } from '@pages/signup'; -import { Login } from '@pages/index'; +import { Login, LoginKakao } from '@pages/index'; const AuthRouter = () => { return ( @@ -10,6 +10,7 @@ const AuthRouter = () => { } /> } /> } /> + } /> ); diff --git a/src/utils/user/validationList.ts b/src/utils/Auth/validationList.ts similarity index 100% rename from src/utils/user/validationList.ts rename to src/utils/Auth/validationList.ts