Skip to content

Commit

Permalink
Cleaning comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashWeaver-Stytch committed May 6, 2024
1 parent 9df2f48 commit a820257
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
1 change: 0 additions & 1 deletion components/EmailSMS/LoginWithEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const LoginWithSMSMFA = () => {
const path = "webauthn";

const isValidEmail = (emailValue: string) => {
// Overly simple email address regex
const regex = /\S+@\S+\.\S+/;
return regex.test(emailValue);
};
Expand Down
15 changes: 3 additions & 12 deletions components/EmailSMS/SMSOTPButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ function formatPhoneNumber(phoneNumber: string): string {

function SMSOTPButton({ phoneNumber }: SMSOTPButtonProps) {
const router = useRouter();
const [openModal, setOpenModal] = useState(false); // State variable to control the modal visibility
const [otp, setOTP] = useState(''); // State variable to store the OTP input by the user
const [methodId, setMethodId] = useState(''); // State variable to store the method ID
const [openModal, setOpenModal] = useState(false);
const [otp, setOTP] = useState('');
const [methodId, setMethodId] = useState('');

const authenticate = async () => {
try {
const response = await sendOTP(phoneNumber);

// Check if response is empty
if (!response) {
console.error('Empty response received from sendOTP');
return;
Expand All @@ -35,30 +34,23 @@ function SMSOTPButton({ phoneNumber }: SMSOTPButtonProps) {
const responseData = await response;
setMethodId(responseData.phone_id);

// Set state to open the modal
setOpenModal(true);

} catch (error) {
// Handle errors here, e.g., display an error message
console.error('Failed to send OTP:', error);
}
};

const handleModalClose = () => {
// Clear OTP input and close the modal
setOTP('');
setOpenModal(false);
};

const handleOTPSubmit = async () => {
try {
// Call the authOTP function with methodID and otp
await authOTP(methodId, otp);

// Redirect to profile page
router.push('./profile');
} catch (error) {
// Handle errors here, e.g., display an error message
console.error('Failed to authenticate OTP:', error);
}
};
Expand All @@ -69,7 +61,6 @@ function SMSOTPButton({ phoneNumber }: SMSOTPButtonProps) {
Authenticate
</button>

{/* Modal for OTP input */}
{openModal && (
<div style={styles.modalOverlay}>
<div style={styles.modal}>
Expand Down
17 changes: 3 additions & 14 deletions components/EmailSMS/SMSRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,37 @@ function formatPhoneNumber(phoneNumber: string): string {
function SMSRegister() {
const router = useRouter();
const [openModalPhone, setOpenModalPhone] = useState(false);
const [openModal, setOpenModal] = useState(false); // State variable to control the OTP modal visibility
const [otp, setOTP] = useState(''); // State variable to store the OTP input by the user
const [openModal, setOpenModal] = useState(false);
const [otp, setOTP] = useState('');
const [phoneNumber, setPhoneNumber] = useState('');
const [methodId, setMethodId] = useState(''); // State variable to store the method ID
const [methodId, setMethodId] = useState('');

const phoneModalOpen = async () => {
// Open the modal for phone number input
setOpenModalPhone(true);
};

const handlePhoneModalClose = () => {
// Close the phone number input modal
setOpenModalPhone(false);
};

const handleOTPModalClose = () => {
// Clear OTP input and close the OTP modal
setOTP('');
setOpenModal(false);
};

const handleOTPSubmit = async () => {
try {
// Call the authOTP function with methodID and otp
await authOTP(methodId, otp);

// Redirect to profile page
router.push('./profile');
} catch (error) {
// Handle errors here, e.g., display an error message
console.error('Failed to authenticate OTP:', error);
}
};

const handlePhoneSubmit = async () => {
try {
// Send OTP with the provided phone number
const response = await sendOTP('+1' + phoneNumber);

// Check if response is empty
if (!response) {
console.error('Empty response received from sendOTP');
return;
Expand All @@ -65,11 +56,9 @@ function SMSRegister() {
setMethodId(responseData.phone_id);
console.log('Method id', responseData.phone_id);

// Close the phone number input modal and open the OTP input modal
setOpenModalPhone(false);
setOpenModal(true);
} catch (error) {
// Handle errors here, e.g., display an error message
console.error('Failed to send OTP:', error);
}
};
Expand Down
2 changes: 0 additions & 2 deletions pages/recipes/api-sms-mfa/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ const Profile = ({ error, user, session, hasRegisteredPhone, superSecretData, ph
} catch {}
};

// Check if there is no user, if so, render <></>
if (!user) {
return <></>;
}

// Render the rest of the JSX (if there is a user)
return (
<div style={styles.container}>
<div style={styles.details}>
Expand Down

0 comments on commit a820257

Please sign in to comment.