Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 14 additions & 0 deletions Web/src/main/orbit/src/pages/login/model/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import authApi from '../api/index';
import { initializeApp } from "firebase/app";

// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAfGC_Ks-MwsgtqQrVKfC9iOdq25Fpj1Hc",
authDomain: "orbit-bbc8f.firebaseapp.com",
projectId: "orbit-bbc8f",
storageBucket: "orbit-bbc8f.firebasestorage.app",
messagingSenderId: "1020053061294",
appId: "1:1020053061294:web:1bfdc7f2c59133689e373f"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

export const useAuthModel = () => {
// 이메일/비밀번호 로그인
Expand Down
54 changes: 16 additions & 38 deletions Web/src/main/orbit/src/pages/signup/api/index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
import axios from 'axios';

// 일반 회원가입 API
//일반 회원가입 api
export const signup = async (formData) => {
const response = await axios.post('${API_BASE_URL}/signup', formData, {
const response = await axios.post(`${"http://localhost:8080/api"}/signup`, formData, {
headers: { 'Content-Type': 'application/json' },
});
return response.data;
};
//이메일 인증코드 보내기
export const sendVerificationCode = async (email) => {
const response = await axios.post(`${"http://localhost:8080/api"}/send-verification-code`, { email }, {
headers: { 'Content-Type': 'application/json' },
});
return response.data;
};
//이메일 인증코드 확인
export const verifyEmailCode = async (email, code) => {
const response = await axios.post(`${"http://localhost:8080/api"}/verify-code`, { email, code }, {
headers: { 'Content-Type': 'application/json' },
});
return response.data;
};

// Google 회원가입 API
// export const googleSignup = async (googleToken) => {
// const response = await axios.post('${API_BASE_URL}/google-signup', { token: googleToken }, {
// headers: { 'Content-Type': 'application/json' },
// });
// return response.data;
// };

// Kakao 회원가입 API
// export const kakaoSignup = () => {
// if (window.Kakao && window.Kakao.Auth) {
// window.Kakao.Auth.authorize({
// redirectUri: 'http://localhost:3000/oauth/callback/kakao',
// });
// } else {
// alert('카카오 SDK 로드 중 오류가 발생했습니다. 잠시 후 다시 시도해주세요.');
// console.error('Kakao SDK is not loaded.');
// }
// };

// NICE 본인인증 API
export const niceAuth = async (phoneNumber) => {
const apiUrl = 'https://nice.checkplus.co.kr/CheckPlusSafeModel/checkplus.cb'; // 나이스 본인 인증 API 엔드포인트
try {
const response = await axios.post(apiUrl, { phoneNumber }, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_NICE_API_KEY', // 나이스에서 제공받은 API 키
},
});
return response.data;
} catch (error) {
console.error('NICE 본인인증 중 오류:', error.response?.data || error.message);
throw error;
}
};

// Naver 로그인 처리는 SignupModel에서 직접 수행합니다.
165 changes: 48 additions & 117 deletions Web/src/main/orbit/src/pages/signup/model/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { signup, googleSignup, kakaoSignup, niceAuth } from '../api/index';
import { signup, sendVerificationCode, verifyEmailCode } from '../api/index';
import Signup from '../ui/index';

const SignupModel = () => {
Expand All @@ -9,74 +9,53 @@ const SignupModel = () => {
email: '',
password: '',
passwordCheck: '',
phoneNumber: '',
verificationCode: '',
});

const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const [success, setSuccess] = useState(false);
const [emailVerified, setEmailVerified] = useState(false);
const [codeSent, setCodeSent] = useState(false);

const navigate = useNavigate();

// const [naverLogin, setNaverLogin] = useState(null);
//
// useEffect(() => {
// // Kakao SDK 로드 및 초기화
// const loadKakaoSDK = () => {
// if (!window.Kakao) {
// const script = document.createElement('script');
// script.src = 'https://developers.kakao.com/sdk/js/kakao.js';
// script.async = true;
// script.onload = () => {
// if (window.Kakao) {
// window.Kakao.init(process.env.REACT_APP_KAKAO_JAVASCRIPT_KEY);
// console.log('Kakao SDK Initialized');
// }
// };
// document.body.appendChild(script);
// } else if (!window.Kakao.isInitialized()) {
// window.Kakao.init(process.env.REACT_APP_KAKAO_JAVASCRIPT_KEY);
// console.log('Kakao SDK Initialized');
// }
// };
//
// // Naver SDK 로드 및 초기화
// const loadNaverSDK = () => {
// const script = document.createElement('script');
// script.src = 'https://static.nid.naver.com/js/naveridlogin_js_sdk_2.0.2.js';
// script.async = true;
// script.onload = () => {
// if (window.naver) {
// // 네이버 로그인 객체 생성 및 초기화
// const naverLogin = new window.naver.LoginWithNaverId({
// clientId: process.env.REACT_APP_NAVER_CLIENT_ID,
// callbackUrl:
// process.env.REACT_APP_NAVER_CALLBACK_URL || 'http://localhost:3000/oauth/callback/naver',
// isPopup: true,
// });
// naverLogin.init();
//
// // 로그인 객체를 상태에 저장
// setNaverLogin(naverLogin);
// console.log('Naver SDK Initialized');
// } else {
// console.error('Naver SDK 로드 실패');
// }
// };
// script.onerror = () => {
// console.error('Naver SDK 로드 실패');
// };
// document.body.appendChild(script);
// };
//
// loadKakaoSDK();
// loadNaverSDK();
// }, []);

const handleChange = (e) => {
const { name, value } = e.target;
setFormData({ ...formData, [name]: value });
};
// 이메일 인증코드 전송 파트
const handleSendCode = async () => {
try {
setLoading(true);
setError('');
await sendVerificationCode(formData.email);
setCodeSent(true);
alert('인증 코드가 이메일로 전송되었습니다.');
} catch (error) {
setError('인증 코드 전송 중 오류가 발생했습니다.');
} finally {
setLoading(false);
}
};
// 이메일 인증코드 확인 파트
const handleVerifyCode = async () => {
try {
setLoading(true);
setError('');
const response = await verifyEmailCode(formData.email, formData.verificationCode);
if (response.verified) {
setEmailVerified(true);
alert('이메일 인증이 완료되었습니다.');
} else {
setError('인증 코드가 잘못되었습니다.');
}
} catch (error) {
setError('이메일 인증 중 오류가 발생했습니다.');
} finally {
setLoading(false);
}
};

const handleSubmit = async (e) => {
e.preventDefault();
Expand All @@ -90,16 +69,13 @@ const SignupModel = () => {
return;
}

try {
// NICE 본인인증
const authResponse = await niceAuth(formData.phoneNumber);
if (!authResponse.success) {
setError('본인인증에 실패했습니다.');
setLoading(false);
return;
}
if (!emailVerified) {
setError('이메일 인증을 완료해주세요.');
setLoading(false);
return;
}

// 회원가입 진행
try {
await signup(formData);
setSuccess(true);
navigate('/login');
Expand All @@ -110,66 +86,21 @@ const SignupModel = () => {
}
};

// const handleGoogleLoginSuccess = async (response) => {
// setLoading(true);
// setError('');
// try {
// await googleSignup(response.credential);
// alert('구글 회원가입 성공!');
// setSuccess(true);
// navigate('/dashboard');
// } catch (error) {
// setError('구글 회원가입 실패: ' + (error.response?.data?.message || error.message));
// } finally {
// setLoading(false);
// }
// };
//
// const handleGoogleLoginError = () => {
// setError('구글 로그인 중 오류가 발생했습니다. 다시 시도해주세요.');
// };
//
// const handleKakaoLogin = () => {
// kakaoSignup();
// };
//
// const handleNaverLogin = () => {
// if (naverLogin) {
// naverLogin.authorize(); // 로그인 프로세스 시작
// } else {
// alert('네이버 SDK 로드 중입니다. 잠시 후 다시 시도해주세요.');
// console.error('Naver Login 객체가 초기화되지 않았습니다.');
// }
// };

const handleNiceAuth = async () => {
setLoading(true);
setError('');
try {
const response = await niceAuth(formData.phoneNumber);
alert('본인인증 성공: ' + response.message);
} catch (error) {
setError('본인인증 실패: ' + (error.response?.data?.message || error.message));
} finally {
setLoading(false);
}
};

return (
<Signup
formData={formData}
handleChange={handleChange}
handleSubmit={handleSubmit}
// handleGoogleLoginSuccess={handleGoogleLoginSuccess}
// handleGoogleLoginError={handleGoogleLoginError}
// handleKakaoLogin={handleKakaoLogin}
// handleNaverLogin={handleNaverLogin}
handleNiceAuth={handleNiceAuth}
handleSendCode={handleSendCode}
handleVerifyCode={handleVerifyCode}
loading={loading}
error={error}
success={success}
codeSent={codeSent}
emailVerified={emailVerified}
/>
);
};

export default SignupModel;

Loading