diff --git a/package.json b/package.json index 998c3b8..cc1a6ca 100644 --- a/package.json +++ b/package.json @@ -65,5 +65,5 @@ "http-proxy-middleware": "^2.0.6", "tailwindcss": "^3.4.0" }, - "proxy": "https://172.20.10.7:8080" + "proxy": "http://test.wasabi.wiki" } diff --git a/src/components/auth/AuthForm.js b/src/components/auth/AuthForm.js index 853e29c..6f7377f 100644 --- a/src/components/auth/AuthForm.js +++ b/src/components/auth/AuthForm.js @@ -39,7 +39,7 @@ const partMap = [ }, ]; -const AuthForm = ({type, form, onChange, onSubmit, onKeyPress, onSelectPart, isOpenModal, emailCode, handleChangeEmailCode, handleSendEmailCode}) => { +const AuthForm = ({type, form, authCode, onChange, onSubmit, onKeyPress, onSelectPart, isOpenModal, handleVerifyEmail, handleChangeAuthCode, handleCheckCode}) => { const [isClicked, setIsClicked] = useState(false); const text = textMap[type]; const {register, handleSubmit, watch, formState: {errors}} = useForm(); @@ -70,7 +70,7 @@ const AuthForm = ({type, form, onChange, onSubmit, onKeyPress, onSelectPart, isO {type === 'signUp' ? @@ -83,12 +83,13 @@ const AuthForm = ({type, form, onChange, onSubmit, onKeyPress, onSelectPart, isO
diff --git a/src/containers/auth/SignUpForm.js b/src/containers/auth/SignUpForm.js index 394370f..50fa3bf 100644 --- a/src/containers/auth/SignUpForm.js +++ b/src/containers/auth/SignUpForm.js @@ -1,17 +1,18 @@ import AuthForm from "../../components/auth/AuthForm"; import {useDispatch, useSelector} from "react-redux"; -import {changeField, changeFieldEmailCode, initializeForm, signUp} from "../../modules/auth"; +import {changeField, initializeForm, signUp} from "../../modules/auth"; import {useEffect, useState} from "react"; -import axios from "axios"; -import {sendEmailCode} from "../../modules/email"; +import {changeAuthCode, verifyEmail} from "../../modules/mail"; const SignUpForm = () => { const [isOpenModal, setIsOpenModal] = useState(false); const dispatch = useDispatch(); - const {form, email, emailCode} = useSelector(({auth}) => ({ + const {form, email, authCode, code, codeError} = useSelector(({auth, mail}) => ({ form: auth.signUp, email: auth.signUp.email, - emailCode: auth.emailCode, + authCode: mail.authCode, + code: mail.code, + codeError: mail.codeError })); const onChange = e => { @@ -26,21 +27,33 @@ const SignUpForm = () => { ); }; - const handleChangeEmailCode = e => { + const handleVerifyEmail = () => { + dispatch(verifyEmail({ + email, + }), + ); + }; + + const handleChangeAuthCode = e => { const {name, value} = e.target; - dispatch(changeFieldEmailCode({ + dispatch(changeAuthCode({ name, value, }), ); }; - const handleSendEmailCode = () => { - dispatch(sendEmailCode({ - email, - }), - ); + const handleCheckCode = () => { + if (code && code.data.authCode) { + if (code.data.authCode === authCode) { + alert('인증되었습니다.'); + } else if (code.data.authCode !== authCode) { + alert('다시 인증해주세요.'); + } + } + + if (codeError) alert(codeError); }; const onSelectPart = e => { @@ -65,13 +78,14 @@ const SignUpForm = () => { return ( ); }; diff --git a/src/lib/api/auth.js b/src/lib/api/auth.js index a3c7aae..3006bc0 100644 --- a/src/lib/api/auth.js +++ b/src/lib/api/auth.js @@ -4,4 +4,6 @@ export const signUp = ({email, password, checkPassword, name, phoneNumber, refer client.post("/auth/signup", ({email, password, checkPassword, name, phoneNumber, referenceUrl, part, organization, motto})); export const login = ({email, password}) => - client.post("/auth/login", ({email, password})); \ No newline at end of file + client.post("/auth/login", ({email, password})); + +export const verifyEmail = ({email}) => client.post('/auth/mail', ({email})); \ No newline at end of file diff --git a/src/lib/api/email.js b/src/lib/api/email.js deleted file mode 100644 index 6219f58..0000000 --- a/src/lib/api/email.js +++ /dev/null @@ -1,3 +0,0 @@ -import client from "./client"; - -export const sendEmailCode = ({email}) => client.post('/email', ({email})); \ No newline at end of file diff --git a/src/lib/api/mailer.js b/src/lib/api/mailer.js deleted file mode 100644 index 78f9b0d..0000000 --- a/src/lib/api/mailer.js +++ /dev/null @@ -1,32 +0,0 @@ -const nodemailer = require('nodemailer'); - -console.log('mailer 실행'); - -module.exports = async (req) => { - console.log('mailer의 req: ' + JSON.stringify(req)); - - const transporter = await nodemailer.createTransport({ // 메일 보내는 객체 - service: 'gmail', - host: 'smtp.gmail.com', // smtp : 네트워크를 통해 이메일을 전송하는 기술 표준 - port: 587, - secure: false, - auth: { - user: process.env.REACT_APP_GMAIL_ADDRESS, - pass: process.env.REACT_APP_GMAIL_PASSWORD, - } - }); - - const mailOption = { - from: `${req.body.email}`, // 받는 곳 - to: `${process.env.REACT_APP_GMAIL_ADDRESS}`, // 보내는 곳 - subject: '[Wasabi] 이메일 인증을 진행해 주세요.', // 메일 제목 - html: `안녕하세요. Wasabi를 이용해주셔서 감사합니다.
가입을 위해 아래 인증번호를 회원가입 화면으로 돌아가 입력해 주세요.
` - }; - - try { - await transporter.sendMail(mailOption); - return 'success'; - } catch (error) { - return error; - } -}; \ No newline at end of file diff --git a/src/modules/auth.js b/src/modules/auth.js index 91e61b4..8256cdf 100644 --- a/src/modules/auth.js +++ b/src/modules/auth.js @@ -6,7 +6,6 @@ import {takeLatest} from "redux-saga/effects"; import client from "../lib/api/client"; const CHANGE_FIELD = 'auth/CHANGE_FIELD'; -const CHANGE_FIELD_EMAIL_CODE = 'auth/CHANGE_FIELD_EMAIL_CODE'; const INITIALIZE_FORM = 'auth/INITIALIZE_FORM'; const [SIGNUP, SIGNUP_SUCCESS, SIGNUP_FAILURE] = createRequestActionTypes( 'auth/SIGNUP', @@ -20,11 +19,6 @@ export const changeField = createAction( ({form, key, value}) => ({form, key, value}) ); -export const changeFieldEmailCode = createAction( - CHANGE_FIELD_EMAIL_CODE, - ({name, value}) => ({name, value}) -); - export const initializeForm = createAction( INITIALIZE_FORM, form => form @@ -66,7 +60,6 @@ const initialState = { organization: '', motto: '', }, - emailCode: '', auth: null, authError: null, }; @@ -77,10 +70,6 @@ const auth = handleActions( state, draft => { draft[form][key] = value; }), - [CHANGE_FIELD_EMAIL_CODE]: (state, {payload: {name, value}}) => ({ - ...state, - [name]: value, - }), [INITIALIZE_FORM]: (state, {payload: form}) => ({ ...state, [form]: initialState[form] diff --git a/src/modules/email.js b/src/modules/email.js deleted file mode 100644 index 64ec7c2..0000000 --- a/src/modules/email.js +++ /dev/null @@ -1,37 +0,0 @@ -import {createAction, handleActions} from "redux-actions"; -import createRequestSaga, {createRequestActionTypes} from "../lib/createRequestSaga"; -import {takeLatest} from "redux-saga/effects"; -import * as emailAPI from "../lib/api/email"; - -const [SEND_EMAIL_CODE, SEND_EMAIL_CODE_SUCCESS, SEND_EMAIL_CODE_FAILURE] = createRequestActionTypes('email/SEND_EMAIL_CODE'); - -export const sendEmailCode = createAction( - SEND_EMAIL_CODE, - ({email}) => ({email}), -); - -const sendEmailCodeSaga = createRequestSaga(SEND_EMAIL_CODE, emailAPI.sendEmailCode); -export function* emailSaga() { - yield takeLatest(SEND_EMAIL_CODE, sendEmailCodeSaga) -} - -const initialState = { - emailCode: null, - emailCodeError: null, -}; - -const email = handleActions( - { - [SEND_EMAIL_CODE_SUCCESS]: (state, {payload: emailCode}) => ({ - ...state, - emailCode, - }), - [SEND_EMAIL_CODE_FAILURE]: (state, {payload: emailCodeError}) => ({ - ...state, - emailCodeError, - }), - }, - initialState, -); - -export default email; \ No newline at end of file diff --git a/src/modules/index.js b/src/modules/index.js index 5bb108e..012906c 100644 --- a/src/modules/index.js +++ b/src/modules/index.js @@ -10,7 +10,7 @@ import myPage, {myPageSaga} from "./mypage"; import admin, {adminSaga} from "./admin"; import search, {searchSaga} from "./search"; import comment, {commentSaga} from "./comment"; -import email, {emailSaga} from "./email"; +import mail, {mailSaga} from "./mail"; const rootReducer = combineReducers({ loading, @@ -23,11 +23,11 @@ const rootReducer = combineReducers({ admin, search, comment, - email, + mail, }); export function* rootSaga() { - yield all([authSaga(), writeSaga(), boardSaga(), likeSaga(), boardsSaga(), myPageSaga(), adminSaga(), searchSaga(), commentSaga(), emailSaga()]); + yield all([authSaga(), writeSaga(), boardSaga(), likeSaga(), boardsSaga(), myPageSaga(), adminSaga(), searchSaga(), commentSaga(), mailSaga()]); } export default rootReducer; \ No newline at end of file diff --git a/src/modules/mail.js b/src/modules/mail.js new file mode 100644 index 0000000..939cea3 --- /dev/null +++ b/src/modules/mail.js @@ -0,0 +1,47 @@ +import {createAction, handleActions} from "redux-actions"; +import createRequestSaga, {createRequestActionTypes} from "../lib/createRequestSaga"; +import {takeLatest} from "redux-saga/effects"; +import * as authAPI from "../lib/api/auth"; + +const CHANGE_AUTH_CODE = 'mail/CHANGE_AUTH_CODE'; +const [VERIFY_EMAIL, VERIFY_EMAIL_SUCCESS, VERIFY_EMAIL_FAILURE] = createRequestActionTypes('mail/VERIFY_EMAIL'); + +export const changeAuthCode = createAction( + CHANGE_AUTH_CODE, + ({name, value}) => ({name, value}) +); +export const verifyEmail = createAction( + VERIFY_EMAIL, + ({email}) => ({email}), +); + +const verifyEmailSaga = createRequestSaga(VERIFY_EMAIL, authAPI.verifyEmail); +export function* mailSaga() { + yield takeLatest(VERIFY_EMAIL, verifyEmailSaga) +} + +const initialState = { + authCode: '', + code: null, + codeError: null, +}; + +const mail = handleActions( + { + [CHANGE_AUTH_CODE]: (state, {payload: {name, value}}) => ({ + ...state, + [name]: value, + }), + [VERIFY_EMAIL_SUCCESS]: (state, {payload: code}) => ({ + ...state, + code, + }), + [VERIFY_EMAIL_FAILURE]: (state, {payload: codeError}) => ({ + ...state, + codeError, + }), + }, + initialState, +); + +export default mail; \ No newline at end of file