(() => { const { EventManager, actions } = ShopbySkin; // DOM 요소 선택 const passwordAuthSection = document.getElementById('password-auth-section'); const phoneChangeSection = document.getElementById('phone-change-section'); const changePhoneBtn = document.getElementById('change-phone-btn'); // 인증 정보 저장용 let authData = null; let currentPassword = null; // 비밀번호 인증 성공 이벤트 EventManager.on('PROCESS_AUTHENTICATION', ({ status }) => { if (status === 'success') { // 비밀번호 가져오기 const passwordInput = document.getElementById('current-password-input'); currentPassword = passwordInput?.value; // 비밀번호 인증 영역 숨기고 변경하기 버튼 표시 passwordAuthSection?.classList.add('phone-number-section--hidden'); phoneChangeSection?.classList.remove('phone-number-section--hidden'); } }); // 변경하기 버튼 클릭 이벤트 - KCP 인증 모달 띄우기 changePhoneBtn?.addEventListener('click', () => { EventManager.fire('OPEN_LAYER_MODAL', { name: 'kcp-sms-authentication', data: { type: 'JOIN_TIME' }, onClose: ({ reason, state }) => { if (reason === 'DID_SUBMIT') { // 인증 성공 시 데이터 저장 authData = state; handleAuthenticationSuccess(state); } }, }); }); // 인증 성공 후 처리 const handleAuthenticationSuccess = async (state) => { try { // 1. 현재 프로필 정보 가져오기 const profile = await actions.queryProfile(); // 2. 인증 정보와 프로필 대조 (이름, 생년월일) const isNameMatch = profile.data.memberName === state.name; const isBirthMatch = profile.data.birthday === state.birthday; if (!isNameMatch || !isBirthMatch) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'CAUTION', message: '인증 정보가 회원 정보와 일치하지 않습니다.', }); return; } // 3. 일치하면 전화번호 변경 API 호출 (비밀번호 포함) await actions.putProfile({ currentPassword: currentPassword, mobileNo: state.phone, }); EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: '전화번호가 변경되었습니다.', onClose: () => location.replace('/pages/my/my-page.html'), }); } catch (error) { console.error('전화번호 변경 실패:', error); EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'CAUTION', message: '전화번호 변경에 실패했습니다.', }); } }; })();