Skip to content

Commit

Permalink
fixing login with 2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
janet-barbie committed Nov 21, 2024
1 parent e239c9e commit 7f73ff8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/pages/LoginWith2fa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export const LOGIN_WITH_2FA = gql`
mutation LoginWithTwoFactorAuthentication(
$email: String!
$otp: String!
$TwoWayVerificationToken: String!
# $TwoWayVerificationToken: String!
) {
loginWithTwoFactorAuthentication(
email: $email
otp: $otp
TwoWayVerificationToken: $TwoWayVerificationToken
# TwoWayVerificationToken: $TwoWayVerificationToken
) {
token
user {
Expand Down Expand Up @@ -84,7 +84,7 @@ const TwoFactorPage: React.FC = () => {

const location = useLocation();
const navigate = useNavigate();
const { email, TwoWayVerificationToken } = location.state || {};
const { email } = location.state || {};
useEffect(() => {
// Update document class and localStorage when theme changes
if (isDark) {
Expand All @@ -97,18 +97,18 @@ const TwoFactorPage: React.FC = () => {
}, [isDark]);

useEffect(() => {
if (!email || !TwoWayVerificationToken) {
if (!email ) {
navigate('/login');
}
}, [email, TwoWayVerificationToken, navigate]);
}, [email, navigate]);

const [loginWithTwoFactorAuthentication] = useMutation<LoginResponse>(
LOGIN_WITH_2FA,
{
onCompleted: async (data) => {
const response = data.loginWithTwoFactorAuthentication;
try {
localStorage.setItem('authToken', response.token);
//localStorage.setItem('authToken', response.token);
localStorage.setItem('user', JSON.stringify(response.user));
await login(response);
await client.resetStore();
Expand Down Expand Up @@ -152,7 +152,7 @@ const TwoFactorPage: React.FC = () => {
variables: {
email,
otp: currentInput.join(''),
TwoWayVerificationToken,
// TwoWayVerificationToken,
},
});
} finally {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Organization/AdminLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ function AdminLogin() {
onCompleted: async (data) => {
if (data.loginUser.otpRequired) {
setOtpRequired(true);
setTwoWayVerificationToken(data.loginUser.TwoWayVerificationToken);
// setTwoWayVerificationToken(data.loginUser.TwoWayVerificationToken);
navigate('/users/LoginWith2fa', {
state: {
email: userInput.email,
TwoWayVerificationToken: data.loginUser.TwoWayVerificationToken,
// TwoWayVerificationToken: data.loginUser.TwoWayVerificationToken,
},})

}else{
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Organization/LoginMutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const LOGIN_MUTATION = gql`
loginUser(loginInput: $loginInput) {
token
otpRequired
TwoWayVerificationToken
user {
id
role
Expand Down

0 comments on commit 7f73ff8

Please sign in to comment.