-
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
3a6b55d
commit 217f358
Showing
21 changed files
with
5,102 additions
and
17,482 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
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
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; | ||
|
Oops, something went wrong.