Skip to content
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

It's dangerous to go alone, take this {captcha} #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions components/ConfirmPhoneModal/ConfirmPhoneModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState, useCallback } from 'react'
import React, { useMemo, useCallback } from 'react'
import ModalWrapper from '../ModalWrapper'
import CustomFormButton from '../CustomFormButton'

Expand All @@ -25,9 +25,13 @@ const unknownErrorMessage = 'Профиль не обновлен: систем
* @param {function} onClose
* @param {function} onSubmit
*/
const ConfirmPhoneModal = ({ visible, errorCode, onSubmit, onClose }) => {
const [verificationCode, setVerificationCode] = useState('')

const ConfirmPhoneModal = ({
visible,
errorCode,
onClose,
verificationCode,
setVerificationCode,
}) => {
const errorMessage = useMemo(() => {
if (errorCode) return ErrorCodesMapper[errorCode] || unknownErrorMessage
return null
Expand Down Expand Up @@ -67,10 +71,8 @@ const ConfirmPhoneModal = ({ visible, errorCode, onSubmit, onClose }) => {
width='49%'
text='Подтвердить'
disabled={isSubmitDisabled}
onClick={() => onSubmit(verificationCode)}
/>
</div>
<div id='phone-confirm-recaptcha' />
</div>
</ModalWrapper>
<style jsx>{`
Expand Down
20 changes: 19 additions & 1 deletion components/UserInfoBox/UserInfoBox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import firebase from 'firebase'
import CustomInput from '../CustomInput'
import Dropdown from '../Dropdown'

Expand Down Expand Up @@ -56,7 +57,19 @@ const UserInfoBox = ({
isCityNameValid(currentCity.value) &&
isTelephoneValid(phone)
) {
onSubmit()
let applicationVerifier
try {
applicationVerifier = new firebase.auth.RecaptchaVerifier(
'phone-confirm-recaptcha',
{
size: 'normal',
}
)
} catch (e) {
applicationVerifier = document.getElementById('phone-confirm-recaptcha')
console.log(e)
}
onSubmit(applicationVerifier)
} else {
alert('Поля не соответствуют требованиям')
}
Expand Down Expand Up @@ -102,9 +115,14 @@ const UserInfoBox = ({
>
Подтвердить
</button>
<div id='phone-confirm-recaptcha' className='captcha' />
</footer>
<style jsx>
{`
.captcha {
z-index: 666666;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно 777777 на удачу

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если прод не доступен - не беда
Введи ..

}

.buttonFooter {
display: flex;
justify-content: space-around;
Expand Down
28 changes: 14 additions & 14 deletions pages/profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const Profile = () => {
const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false)
const [phoneChangeError, setPhoneChangeError] = useState(null)

const [verificationCode, setVerificationCode] = useState('')

const resetFields = () => {
if (currentUser) {
setNameInputState(currentUser.name)
Expand Down Expand Up @@ -139,29 +141,24 @@ const Profile = () => {
setPhoneChangeError(null)
}

const onSubmitPhoneChange = verificationCode => {
let applicationVerifier
try {
applicationVerifier = new firebase.auth.RecaptchaVerifier(
'phone-confirm-recaptcha',
{
size: 'normal',
}
)
} catch (e) {
applicationVerifier = document.getElementById('phone-confirm-recaptcha')
}
const onSubmitPhoneChange = applicationVerifier => {
console.log('STAS')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это точно убрать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не ну без Стасяна тут точно не разобраться

try {
console.log(firebase.auth().currentUser)
console.log(phoneInputState)
const provider = new firebase.auth.PhoneAuthProvider()
provider
.verifyPhoneNumber(phoneInputState, applicationVerifier)
.then(verificationId => {
try {
console.log(verificationId)
console.log(firebase.auth().currentUser.phoneNumber)
const phoneCredential = firebase.auth.PhoneAuthProvider.credential(
verificationId,
verificationCode
)
firebase.auth().currentUser.updatePhoneNumber(phoneCredential)
console.log(firebase.auth().currentUser.phoneNumber)
} catch (e) {
setPhoneChangeError(e.code)
}
Expand All @@ -179,7 +176,7 @@ const Profile = () => {
}
}

const onSubmit = async () => {
const onSubmit = async applicationVerifier => {
if (
currentUser.name === nameInputState &&
currentUser.cityId === cityInputState.id &&
Expand All @@ -201,6 +198,7 @@ const Profile = () => {
if (isPhoneUpdated) {
setIsConfirmModalVisible(true)
setProfileData(preparedData)
onSubmitPhoneChange(applicationVerifier)
} else {
updateProfile(preparedData)
}
Expand All @@ -218,9 +216,11 @@ const Profile = () => {
<Header />
<ConfirmPhoneModal
visible={isConfirmModalVisible}
onSubmit={onSubmitPhoneChange}
onClose={onClosePhoneConfirmModal}
errorCode={phoneChangeError}
verificationCode={verificationCode}
setVerificationCode={setVerificationCode}
onClick={onSubmitPhoneChange}
/>
<div className='content'>
<header className='mainHeader'>Личный кабинет</header>
Expand Down