This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const user = useUser(); | |
const registerFormHandler = async ({ fullname, password }) => { | |
if (user && user.phoneNumber) { | |
const email = convertPhoneToEmail(user.phoneNumber); | |
const credential = EmailAuthProvider.credential(email, password); | |
const userCred = await linkWithCredential(user, credential); | |
await updateProfile(userCred.user, { | |
displayName: fullname, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const verifyCode = ({ code }) => { | |
const credential = PhoneAuthProvider.credential(verificationId, code); | |
signInWithCredential(auth, credential).then((userCredential) => { | |
console.log(userCredential); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const convertPhoneToEmail = (phone: string) => { | |
// replacing special characters( +,-, (, ), and #. ) to alphabet chars | |
console.log(phone); | |
const cleanedPhone = phone | |
.replace("(", "A") | |
.replace(")", "B") | |
.replace(",", "C") | |
.replace("#", "D") | |
.replace(" ", "E"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sendVerificationCode = async () => { | |
setLoading(true); | |
try { | |
const email = convertPhoneToEmail(phoneNumber); | |
const providers = await fetchSignInMethodsForEmail(auth, email); | |
if (providers.length == 0) { | |
const confirmationResult = await signInWithPhoneNumber( | |
auth, | |
phoneNumber, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import { Button, Form } from "antd"; | |
import { RecaptchaVerifier, signInWithPhoneNumber } from "firebase/auth"; | |
import { auth } from "../../firebase"; | |
import { PhoneNumberInput } from "./phone-input"; | |
export default function PhoneVerification({ codeSent }) { | |
const [phoneNumber, setPhoneNumber] = useState<string>(""); | |
const [loading, setLoading] = useState(false); | |
const [isPhoneEmpty, setIsPhoneEmpty] = useState<boolean>(true); |