Skip to content

Commit

Permalink
Merge pull request #1520 from hngx-org/bug-fixes
Browse files Browse the repository at this point in the history
fixed issues enabling and disabling 2fa on settings page
  • Loading branch information
Homoakin619 authored Dec 11, 2023
2 parents 46da43b + ade71df commit 2a6d783
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
1 change: 0 additions & 1 deletion http/checkout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CartItemProps } from '../@types';
import { useAuth } from '../context/AuthContext';
import $http from './axios';
import axios from 'axios';

Expand Down
87 changes: 79 additions & 8 deletions modules/portfolio/component/portfolioSettingsComponents/2fa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,72 @@ const Handling2FA = (props: close) => {
}
};

const handleEnable2FA = async () => {
setLoading(true);
const unFilled = digits.filter((o) => o === '').map((o) => o);
setFill(true);
try {
const token = auth?.token as string;
const enableResponse = await enabled2FA({ token });
if (enableResponse.status === 200) {
handleAuth(enableResponse.data);
console.log(enableResponse);
setLoading(false);
setOpen2Fa(false);
notify({
message: '2FA Enabled',
type: 'success',
});
} else {
setLoading(false);
notify({
message: 'Invalid Code',
type: 'error',
});
}
} catch (error) {
setLoading(false);
notify({
message: 'error occurred',
type: 'error',
});
}
};


const handleDisable2FA = async () => {
setLoading(true);
const unFilled = digits.filter((o) => o === '').map((o) => o);
setFill(true);
try {
const token = auth?.token as string;
const enableResponse = await disable2FA({ token });
if (enableResponse.status === 200) {
handleAuth(enableResponse.data);
console.log(enableResponse);
setLoading(false);
setOpen2Fa(false);
notify({
message: '2FA Disabled',
type: 'success',
});
} else {
setLoading(false);
notify({
message: 'Invalid Code',
type: 'error',
});
}
} catch (error) {
setLoading(false);
notify({
message: 'error occurred',
type: 'error',
});
}
};


const handleVerifyAndEnable2FA = async () => {
setLoading(true);
const unFilled = digits.filter((o) => o === '').map((o) => o);
Expand Down Expand Up @@ -221,9 +287,13 @@ const Handling2FA = (props: close) => {

<label
onClick={() => {
setOpen2Fa((prv) => !prv);
!lgModal && props.setCloseAcc(false);
}}
if(!auth?.user?.twoFactorAuth) {
setOpen2Fa((prv) => !prv);
!lgModal && props.setCloseAcc(false);
} else {
handleDisable2FA()
}
}}
className="relative inline-flex items-center cursor-pointer mx-end"
>
<input
Expand All @@ -233,8 +303,8 @@ const Handling2FA = (props: close) => {
disabled
checked={auth?.user?.twoFactorAuth || auth?.user?.two_factor_auth}
onChange={() => {
setOpen2Fa((prv) => !prv);
!lgModal && props.setCloseAcc(false);
// setOpen2Fa((prv) => !prv);
// !lgModal && props.setCloseAcc(false);
}}
className="sr-only peer"
/>
Expand All @@ -259,7 +329,7 @@ const Handling2FA = (props: close) => {
{!props.closeAcc && !countinue2Fa && (
<div className=" relative md:hidden font-manropeL max-w-[440px] text-[14px] py-[40px]">
<h3 className="w-full text-start mb-[8px] text-[24px] text-[#252525] font-manropeB">Turn on 2FA </h3>
<p>Enhance your security by enabling a verification code to verify your identity</p>
<p>Enhance your security by enabling a verification code to verify your identity Setting</p>

<label htmlFor="" className="flex my-[24px] relative flex-col gap-[6px] text-[ #344054]">
Email
Expand Down Expand Up @@ -367,7 +437,7 @@ const Handling2FA = (props: close) => {
<CloseCircle size="20" color="#009254" />
</button>
<h3 className="w-full text-center mb-[8px] text-[#252525] font-manropeB">Turn on 2FA </h3>
<p>Enhance your security by enabling a verification code to verify your identity</p>
<p>Enhance your security by enabling a verification code to verify your identity Other</p>

<label htmlFor="" className="flex my-[24px] relative flex-col gap-[6px] text-[ #344054]">
Email
Expand Down Expand Up @@ -404,7 +474,8 @@ const Handling2FA = (props: close) => {
size={'sm'}
isLoading={loading}
spinnerColor="#39D98A"
onClick={handleResend2FACode}
// onClick={handleResend2FACode}
onClick={handleEnable2FA}
className="w-full bg-brand-green-primary border-[0px] hover:bg-brand-green-hover text-white-100 text-center
font-manropeB text-[16px] py-[14px] rounded-lg "
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function UpdatePassword() {
(formData: any) => {
// This function will be called when you call the mutate function
// https://zuri-auth.up.railway.app/api/auth/api/authorize
return axios.post('https://zuri-auth.up.railway.app/api/auth/api/auth/reset-password/change', formData);
return axios.put('https://zuri-auth.up.railway.app/api/auth/api/auth/reset-password/change', formData);
},
{
// onSuccess callback is triggered when the mutation is successful
Expand Down

1 comment on commit 2a6d783

@vercel
Copy link

@vercel vercel bot commented on 2a6d783 Dec 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

zuriportfolio-frontend – ./

zuriportfolio.vercel.app
zuriportfolio-frontend-zuri-team.vercel.app
zuriportfolio-frontend-git-dev-zuri-team.vercel.app

Please sign in to comment.