mirror of
https://github.com/chatwoot/chatwoot.git
synced 2026-06-13 21:01:16 +08:00
# Pull Request Template ## Description This PR fixes the non-functional resend confirmation feature on the V3 login page where clicking "Resend confirmation" did nothing. The issue was caused by the V3 store not having the `resendConfirmation` action that the login page was trying to dispatch. **Key improvements:** - Fixed V3 store integration by importing `resendConfirmation` directly from auth API - Added comprehensive UX improvements with loading states and 60-second cooldown timer - Implemented environment-aware debug logging for development - Added proper error handling and user feedback - Enhanced backend test coverage **Context:** Users with unconfirmed accounts were unable to resend confirmation emails from the login page, creating a poor user experience and potential support burden. Fixes #3157 ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? **Backend Testing:** - All existing resend_confirmation tests passing (7/7) - Added comprehensive new test suite in `spec/requests/api/v1/resend_confirmation_spec.rb` - API endpoint returns 200 OK responses in ~0.39 seconds - Email delivery confirmed via SMTP with test user `[email protected]` **Frontend Testing:** - All frontend tests passing - ESLint compliant code with automatic corrections applied - Manual testing of login page functionality: - 60-second cooldown timer with countdown display - Error handling with user-friendly messages - Development logging works (console output in dev mode only) **Test Configuration:** - Ruby/Rails backend with RSpec test suite - Vue.js frontend with Jest/testing-library - Development environment with Gmail SMTP configured - Test user: unconfirmed account `[email protected]` **Reproduction Steps:** 1. Navigate to login page with unconfirmed account 2. Click "Resend confirmation link" 3. Observe loading state, API call, and success feedback 4. Verify 60-second cooldown prevents spam 5. Check email delivery. ## Checklist: - [ ] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sivin Varghese <[email protected]> Co-authored-by: Sojan Jose <[email protected]> Co-authored-by: Sony Mathew <[email protected]> Co-authored-by: Sony Mathew <[email protected]>
106 lines
2.7 KiB
JavaScript
106 lines
2.7 KiB
JavaScript
import {
|
|
setAuthCredentials,
|
|
throwErrorMessage,
|
|
clearLocalStorageOnLogout,
|
|
parseAPIErrorResponse,
|
|
} from 'dashboard/store/utils/api';
|
|
import wootAPI from './apiClient';
|
|
import {
|
|
getLoginRedirectURL,
|
|
getCredentialsFromEmail,
|
|
} from '../helpers/AuthHelper';
|
|
|
|
export const login = async ({
|
|
ssoAccountId,
|
|
ssoConversationId,
|
|
...credentials
|
|
}) => {
|
|
try {
|
|
const response = await wootAPI.post('auth/sign_in', credentials);
|
|
|
|
// Check if MFA is required
|
|
if (response.status === 206 && response.data.mfa_required) {
|
|
// Return MFA data instead of throwing error
|
|
return {
|
|
mfaRequired: true,
|
|
mfaToken: response.data.mfa_token,
|
|
};
|
|
}
|
|
|
|
setAuthCredentials(response);
|
|
clearLocalStorageOnLogout();
|
|
window.location = getLoginRedirectURL({
|
|
ssoAccountId,
|
|
ssoConversationId,
|
|
user: response.data.data,
|
|
});
|
|
return null;
|
|
} catch (error) {
|
|
// Check if it's an MFA required response
|
|
if (error.response?.status === 206 && error.response?.data?.mfa_required) {
|
|
return {
|
|
mfaRequired: true,
|
|
mfaToken: error.response.data.mfa_token,
|
|
};
|
|
}
|
|
const loginError = new Error(parseAPIErrorResponse(error));
|
|
loginError.errorCode = error.response?.data?.error_code;
|
|
throw loginError;
|
|
}
|
|
};
|
|
|
|
export const register = async creds => {
|
|
try {
|
|
const { fullName, accountName } = getCredentialsFromEmail(creds.email);
|
|
const response = await wootAPI.post('api/v1/accounts.json', {
|
|
account_name: accountName,
|
|
user_full_name: fullName,
|
|
email: creds.email,
|
|
password: creds.password,
|
|
h_captcha_client_response: creds.hCaptchaClientResponse,
|
|
});
|
|
return response.data;
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const resendConfirmation = async ({ email, hCaptchaClientResponse }) => {
|
|
return wootAPI.post('resend_confirmation', {
|
|
email,
|
|
h_captcha_client_response: hCaptchaClientResponse,
|
|
});
|
|
};
|
|
|
|
export const verifyPasswordToken = async ({ confirmationToken }) => {
|
|
try {
|
|
const response = await wootAPI.post('auth/confirmation', {
|
|
confirmation_token: confirmationToken,
|
|
});
|
|
setAuthCredentials(response);
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
}
|
|
};
|
|
|
|
export const setNewPassword = async ({
|
|
resetPasswordToken,
|
|
password,
|
|
confirmPassword,
|
|
}) => {
|
|
try {
|
|
const response = await wootAPI.put('auth/password', {
|
|
reset_password_token: resetPasswordToken,
|
|
password_confirmation: confirmPassword,
|
|
password,
|
|
});
|
|
setAuthCredentials(response);
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
}
|
|
};
|
|
|
|
export const resetPassword = async ({ email }) =>
|
|
wootAPI.post('auth/password', { email });
|