Skip to content

Commit 999e800

Browse files
committed
fixing login with 2fa
1 parent 8f45bdb commit 999e800

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

src/pages/LoginWith2fa.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export const LOGIN_WITH_2FA = gql`
4242
mutation LoginWithTwoFactorAuthentication(
4343
$email: String!
4444
$otp: String!
45-
$TwoWayVerificationToken: String!
45+
# $TwoWayVerificationToken: String!
4646
) {
4747
loginWithTwoFactorAuthentication(
4848
email: $email
4949
otp: $otp
50-
TwoWayVerificationToken: $TwoWayVerificationToken
50+
# TwoWayVerificationToken: $TwoWayVerificationToken
5151
) {
5252
token
5353
user {
@@ -84,7 +84,7 @@ const TwoFactorPage: React.FC = () => {
8484

8585
const location = useLocation();
8686
const navigate = useNavigate();
87-
const { email, TwoWayVerificationToken } = location.state || {};
87+
const { email } = location.state || {};
8888
useEffect(() => {
8989
// Update document class and localStorage when theme changes
9090
if (isDark) {
@@ -97,30 +97,30 @@ const TwoFactorPage: React.FC = () => {
9797
}, [isDark]);
9898

9999
useEffect(() => {
100-
if (!email || !TwoWayVerificationToken) {
100+
if (!email ) {
101101
navigate('/login');
102102
}
103-
}, [email, TwoWayVerificationToken, navigate]);
103+
}, [email, navigate]);
104104

105105
const [loginWithTwoFactorAuthentication] = useMutation<LoginResponse>(
106106
LOGIN_WITH_2FA,
107107
{
108108
onCompleted: async (data) => {
109109
const response = data.loginWithTwoFactorAuthentication;
110110
try {
111-
localStorage.setItem('authToken', response.token);
111+
//localStorage.setItem('authToken', response.token);
112112
localStorage.setItem('user', JSON.stringify(response.user));
113113
await login(response);
114114
await client.resetStore();
115115
toast.success(response.message);
116116

117117
const rolePaths: Record<string, string> = {
118-
superAdmin: '/dashboard',
118+
superAdmin: '/organizations',
119119
admin: '/trainees',
120120
coordinator: '/trainees',
121121
manager: '/dashboard',
122122
ttl: '/ttl-trainees',
123-
trainee: '/dashboard',
123+
trainee: '/performance',
124124
};
125125

126126
const redirectPath = rolePaths[response.user.role] || '/dashboard';
@@ -152,7 +152,7 @@ const TwoFactorPage: React.FC = () => {
152152
variables: {
153153
email,
154154
otp: currentInput.join(''),
155-
TwoWayVerificationToken,
155+
// TwoWayVerificationToken,
156156
},
157157
});
158158
} finally {

src/pages/Organization/AdminLogin.tsx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,46 @@ function AdminLogin() {
7575
},
7676
},
7777

78+
7879
/* istanbul ignore next */
7980
onCompleted: async (data) => {
8081
if (data.loginUser.otpRequired) {
8182
setOtpRequired(true);
82-
setTwoWayVerificationToken(data.loginUser.TwoWayVerificationToken);
83+
// setTwoWayVerificationToken(data.loginUser.TwoWayVerificationToken);
8384
navigate('/users/LoginWith2fa', {
8485
state: {
8586
email: userInput.email,
86-
TwoWayVerificationToken: data.loginUser.TwoWayVerificationToken,
87-
},
88-
});
89-
} else {
90-
/* istanbul ignore next */
91-
toast.success(data.addMemberToCohort);
92-
/* istanbul ignore next */
93-
login(data.loginUser);
94-
/* istanbul ignore next */
95-
await client.resetStore();
96-
/* istanbul ignore next */
97-
toast.success(t(`Welcome`) as ToastContent<unknown>);
87+
// TwoWayVerificationToken: data.loginUser.TwoWayVerificationToken,
88+
},})
89+
90+
}else{
9891
/* istanbul ignore next */
99-
if (data.loginUser) {
100-
redirect
101-
? navigate(`${redirect}`)
102-
: data.loginUser.user.role === 'superAdmin'
103-
? navigate(`/dashboard`)
104-
: data.loginUser.user.role === 'admin'
105-
? navigate(`/trainees`)
106-
: data.loginUser.user.role === 'coordinator'
107-
? navigate(`/trainees`)
108-
: data.loginUser.user.role === 'manager'
109-
? navigate(`/dashboard`)
110-
: data.loginUser.user.role === 'ttl'
111-
? navigate('/ttl-trainees')
112-
: navigate('/dashboard');
113-
} else {
114-
navigate('/dashboard');
115-
}
92+
toast.success(data.addMemberToCohort);
93+
/* istanbul ignore next */
94+
login(data.loginUser);
95+
/* istanbul ignore next */
96+
await client.resetStore();
97+
/* istanbul ignore next */
98+
toast.success(t(`Welcome`) as ToastContent<unknown>);
99+
/* istanbul ignore next */
100+
if (data.loginUser) {
101+
redirect
102+
? navigate(`${redirect}`)
103+
: data.loginUser.user.role === 'superAdmin'
104+
? navigate(`/dashboard`)
105+
: data.loginUser.user.role === 'admin'
106+
? navigate(`/trainees`)
107+
: data.loginUser.user.role === 'coordinator'
108+
? navigate(`/trainees`)
109+
: data.loginUser.user.role === 'manager'
110+
? navigate(`/dashboard`)
111+
: data.loginUser.user.role === 'ttl'
112+
? navigate('/ttl-trainees')
113+
: navigate('/performance');
114+
} else {
115+
navigate('/dashboard');
116116
}
117-
},
117+
}},
118118
onError: (err) => {
119119
/* istanbul ignore next */
120120
console.log(err.message);

src/pages/Organization/LoginMutation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const LOGIN_MUTATION = gql`
55
loginUser(loginInput: $loginInput) {
66
token
77
otpRequired
8-
TwoWayVerificationToken
8+
99
user {
1010
id
1111
role

0 commit comments

Comments
 (0)