updates
This commit is contained in:
@@ -38,6 +38,7 @@ const StepUpAuthModal: React.FC<StepUpAuthModalProps> = ({
|
||||
actionDescription = 'this action',
|
||||
}) => {
|
||||
const { userInfo } = useAuthStore();
|
||||
const isAdmin = (userInfo?.role || (userInfo as any)?.role_name)?.toLowerCase() === 'admin';
|
||||
const [verificationMethod, setVerificationMethod] = useState<'mfa' | 'password'>('mfa');
|
||||
const [isVerifying, setIsVerifying] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -92,9 +93,13 @@ const StepUpAuthModal: React.FC<StepUpAuthModalProps> = ({
|
||||
setIsVerifying(true);
|
||||
setError(null);
|
||||
|
||||
const response = await accountantSecurityService.verifyStepUp({
|
||||
const response = await (isAdmin
|
||||
? accountantSecurityService.verifyAdminStepUp({
|
||||
mfa_token: data.mfaToken,
|
||||
})
|
||||
: accountantSecurityService.verifyStepUp({
|
||||
mfa_token: data.mfaToken,
|
||||
});
|
||||
}));
|
||||
|
||||
if (response.status === 'success' && response.data.step_up_completed) {
|
||||
toast.success('Identity verified successfully');
|
||||
@@ -106,10 +111,16 @@ const StepUpAuthModal: React.FC<StepUpAuthModalProps> = ({
|
||||
throw new Error('Step-up verification failed');
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Prevent page refresh by ensuring error is caught and handled
|
||||
const errorMessage =
|
||||
error.response?.data?.detail || error.response?.data?.message || 'Failed to verify identity. Please try again.';
|
||||
error.response?.data?.detail ||
|
||||
(typeof error.response?.data === 'string' ? error.response.data : null) ||
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
'Failed to verify identity. Please try again.';
|
||||
setError(errorMessage);
|
||||
toast.error(errorMessage);
|
||||
// Don't close modal on error - let user try again
|
||||
} finally {
|
||||
setIsVerifying(false);
|
||||
}
|
||||
@@ -120,9 +131,13 @@ const StepUpAuthModal: React.FC<StepUpAuthModalProps> = ({
|
||||
setIsVerifying(true);
|
||||
setError(null);
|
||||
|
||||
const response = await accountantSecurityService.verifyStepUp({
|
||||
const response = await (isAdmin
|
||||
? accountantSecurityService.verifyAdminStepUp({
|
||||
password: data.password,
|
||||
})
|
||||
: accountantSecurityService.verifyStepUp({
|
||||
password: data.password,
|
||||
});
|
||||
}));
|
||||
|
||||
if (response.status === 'success' && response.data.step_up_completed) {
|
||||
toast.success('Identity verified successfully');
|
||||
@@ -134,10 +149,16 @@ const StepUpAuthModal: React.FC<StepUpAuthModalProps> = ({
|
||||
throw new Error('Step-up verification failed');
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Prevent page refresh by ensuring error is caught and handled
|
||||
const errorMessage =
|
||||
error.response?.data?.detail || error.response?.data?.message || 'Invalid password. Please try again.';
|
||||
error.response?.data?.detail ||
|
||||
(typeof error.response?.data === 'string' ? error.response.data : null) ||
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
'Invalid password. Please try again.';
|
||||
setError(errorMessage);
|
||||
toast.error(errorMessage);
|
||||
// Don't close modal on error - let user try again
|
||||
} finally {
|
||||
setIsVerifying(false);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,15 @@ class AccountantSecurityService {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async verifyAdminStepUp(data: {
|
||||
mfa_token?: string;
|
||||
password?: string;
|
||||
session_token?: string;
|
||||
}): Promise<{ status: string; data: { step_up_completed: boolean } }> {
|
||||
const response = await apiClient.post('/auth/admin/step-up/verify', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async getSessions(): Promise<{ status: string; data: { sessions: AccountantSession[] } }> {
|
||||
const response = await apiClient.get('/accountant/security/sessions');
|
||||
return response.data;
|
||||
|
||||
Reference in New Issue
Block a user