-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fcdb3e
commit 9ac9a66
Showing
11 changed files
with
585 additions
and
14,820 deletions.
There are no files selected for viewing
Submodule atlp-pulse-fn
added at
db0c6f
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint-disable */ | ||
// mutations.ts | ||
import gql from 'graphql-tag'; | ||
|
||
export const ENABLE_TWO_FACTOR_AUTH = gql` | ||
mutation EnableTwoFactorAuth($email: String!) { | ||
enableTwoFactorAuth(email: $email) | ||
} | ||
`; | ||
|
||
export const DISABLE_TWO_FACTOR_AUTH = gql` | ||
mutation DisableTwoFactorAuth($email: String!) { | ||
disableTwoFactorAuth(email: $email) | ||
} | ||
`; | ||
|
||
export const VERIFY_ONE_TIME_CODE = gql` | ||
mutation VerifyOneTimeCode($email: String!, $code: String!) { | ||
verifyOneTimeCode(email: $email, code: $code) | ||
} | ||
`; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable */ | ||
import React, { useState } from 'react'; | ||
import { useMutation, useQuery } from '@apollo/client'; | ||
import { ENABLE_TWO_FACTOR_AUTH } from '../../Mutations/Twofactor2fa'; | ||
import { toast } from 'react-toastify'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import VerifyOneTimeCodeComponent from "../../components/twofactor/Verify2fa"; | ||
import { GET_PROFILE } from '../../Mutations/User'; // Import your GET_PROFILE query | ||
import Loader1 from '../../components/loaders/loader2/index'; // Import your loader component | ||
|
||
const EnableTwoFactorAuthComponent: React.FC = () => { | ||
const [isTwoFactorEnabled, setIsTwoFactorEnabled] = useState(false); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
// Fetch user's profile to get the email | ||
const { loading, error, data } = useQuery(GET_PROFILE); | ||
|
||
const [enableTwoFactorAuth] = useMutation(ENABLE_TWO_FACTOR_AUTH); | ||
|
||
const handleEnableTwoFactorAuth = async () => { | ||
try { | ||
setIsLoading(true); | ||
|
||
// Check if the GET_PROFILE query has loaded | ||
if (loading) { | ||
toast.error('Profile data is loading. Please wait.'); | ||
setIsLoading(false); | ||
return; | ||
} | ||
if (error) { | ||
toast.error('Error fetching profile data. Please try again.'); | ||
setIsLoading(false); | ||
return; | ||
} | ||
|
||
// Extract the email from the profile data | ||
const userProfile = data.getProfile; | ||
const userProfileEmail = userProfile.user.email; | ||
|
||
// Send the OTP to the user's email | ||
const response = await enableTwoFactorAuth({ | ||
variables: { email: userProfileEmail }, | ||
}); | ||
|
||
console.log(response.data.enableTwoFactorAuth); | ||
toast.success('OTP check email sent! Check your inbox.'); | ||
setIsTwoFactorEnabled(true); | ||
} catch (error) { | ||
console.error(error); | ||
toast.error('Error sending OTP check email. Please try again.'); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='border-b border-gray-400 pt-2 pb-1'> | ||
<button onClick={handleEnableTwoFactorAuth} disabled={isLoading}> | ||
{isLoading ? <Loader1 /> : 'Enable 2FA'} | ||
</button> | ||
|
||
{isTwoFactorEnabled && <VerifyOneTimeCodeComponent />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default EnableTwoFactorAuthComponent; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable */ | ||
import React, { useState } from 'react'; | ||
import { useMutation, useQuery } from '@apollo/client'; | ||
import { toast, ToastContainer } from 'react-toastify'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import { DISABLE_TWO_FACTOR_AUTH } from '../../Mutations/Twofactor2fa'; | ||
import Loader1 from '../../components/loaders/loader2/index'; // Import your loader component | ||
import { GET_PROFILE } from '../../Mutations/User'; // Import your GET_PROFILE query | ||
|
||
const DisableTwoFactorAuthComponent: React.FC = () => { | ||
const [isTwoFactorDisabled, setIsTwoFactorDisabled] = useState(false); | ||
const [loading, setLoading] = useState(false); // State to manage loading state | ||
|
||
// Fetch user's profile to get the email | ||
const { error, data } = useQuery(GET_PROFILE); | ||
|
||
const [disableTwoFactorAuth] = useMutation(DISABLE_TWO_FACTOR_AUTH); | ||
|
||
const handleDisableTwoFactorAuth = async () => { | ||
try { | ||
// Check if the GET_PROFILE query has loaded | ||
if (loading) { | ||
toast.error('Profile data is loading. Please wait.'); | ||
return; | ||
} | ||
if (error) { | ||
toast.error('Error fetching profile data. Please try again.'); | ||
return; | ||
} | ||
|
||
setLoading(true); // Set loading state to true | ||
|
||
// Extract the email from the profile data | ||
const userProfile = data.getProfile; | ||
const userProfileEmail = userProfile.user.email; | ||
|
||
// Disable two-factor authentication using the user's email | ||
const response = await disableTwoFactorAuth({ | ||
variables: { email: userProfileEmail }, | ||
}); | ||
|
||
console.log(response.data.disableTwoFactorAuth); | ||
toast.success('2FA Disabled'); // Display success toast | ||
setIsTwoFactorDisabled(true); | ||
} catch (error) { | ||
console.error(error); | ||
toast.error('Error disabling 2FA'); // Display error toast | ||
} finally { | ||
setLoading(false); // Set loading state back to false when done | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='border-b border-gray-400 pt-2 pb-1 text-black-400'> | ||
<button onClick={handleDisableTwoFactorAuth} disabled={loading}> | ||
{loading ? <Loader1 /> : 'Disable 2FA'} | ||
</button> | ||
<ToastContainer /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DisableTwoFactorAuthComponent; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* eslint-disable */ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useMutation, useQuery } from '@apollo/client'; | ||
import { toast } from 'react-toastify'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import Loader1 from '../../components/loaders/loader2/index'; | ||
import { VERIFY_ONE_TIME_CODE } from '../../Mutations/Twofactor2fa'; | ||
import { GET_PROFILE } from '../../Mutations/User'; | ||
|
||
const VerifyOneTimeCodeComponent: React.FC = () => { | ||
const [code, setCode] = useState(''); | ||
const [isCodeVerified, setIsCodeVerified] = useState(false); | ||
const [isModalOpen, setIsModalOpen] = useState(true); | ||
const [isVerifying, setIsVerifying] = useState(false); | ||
|
||
// Fetch user's profile to get the email | ||
const { loading, error, data } = useQuery(GET_PROFILE); | ||
|
||
const [verifyOneTimeCode] = useMutation(VERIFY_ONE_TIME_CODE); | ||
|
||
const closeModal = () => { | ||
setIsModalOpen(false); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isModalOpen) { | ||
// The modal is open, you can place any code to run when it opens here. | ||
} | ||
}, [isModalOpen]); | ||
|
||
const handleVerifyOneTimeCode = async () => { | ||
try { | ||
setIsVerifying(true); | ||
|
||
if (loading) { | ||
toast.error('Profile data is loading. Please wait.'); | ||
return; | ||
} | ||
if (error) { | ||
toast.error('Error fetching profile data. Please try again.'); | ||
return; | ||
} | ||
|
||
const userProfile = data.getProfile; | ||
const userProfileEmail = userProfile.user.email; | ||
|
||
const response = await verifyOneTimeCode({ | ||
variables: { email: userProfileEmail, code }, | ||
}); | ||
|
||
console.log(response.data.verifyOneTimeCode); | ||
|
||
if (response.data.verifyOneTimeCode) { | ||
toast.success('OTP verified successfully'); | ||
setIsCodeVerified(true); | ||
closeModal(); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
toast.error('Error verifying OTP'); | ||
} finally { | ||
setIsVerifying(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
{isModalOpen && ( | ||
<div className="fixed inset-0 flex items-center justify-center z-50"> | ||
<div className="absolute inset-0 bg-gray-900 opacity-75"></div> | ||
<div className="bg-white p-4 rounded-lg shadow-md z-10"> | ||
<button onClick={closeModal} className="absolute top-2 right-2 text-gray-600"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> | ||
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" /> | ||
</svg> | ||
</button> | ||
<input | ||
type="text" | ||
value={code} | ||
onChange={(e) => setCode(e.target.value)} | ||
placeholder="Enter one-time code" | ||
className="border border-gray-300 p-2 w-full rounded text-black" | ||
/> | ||
<button | ||
onClick={handleVerifyOneTimeCode} | ||
className="bg-blue-500 text-white p-2 rounded mt-4" | ||
disabled={isVerifying} // Disable the button while verifying | ||
> | ||
{isVerifying ? ( | ||
<Loader1 /> // Show the loader inside the button | ||
) : ( | ||
'Verify Code' | ||
)} | ||
</button> | ||
{isCodeVerified && <div className="mt-4">OTP Verified Successfully!</div>} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default VerifyOneTimeCodeComponent; |
This file contains 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
This file contains 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
Oops, something went wrong.