commit
8ad5067f79
@ -132,17 +132,33 @@ export const useAuth = ({ funnelId, googleAnalyticsId, registrationData }: IUseA
|
||||
} catch (err) {
|
||||
// Extract error message and suggestion from API error
|
||||
if (err instanceof ApiError && err.data) {
|
||||
const errorData = err.data as { errors?: Array<{ msg: string; path: string }> };
|
||||
const emailError = errorData.errors?.find(e => e.path === 'email');
|
||||
const errorData = err.data as {
|
||||
errors?: Array<{ msg: string; path: string }>;
|
||||
status?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
if (emailError) {
|
||||
setError(emailError.msg);
|
||||
// Handle service error format: { status: "error", message: "..." }
|
||||
if (errorData.status === 'error' && errorData.message) {
|
||||
setError(errorData.message);
|
||||
setSuggestedEmail(null);
|
||||
}
|
||||
// Handle express-validator format: { errors: [{ msg, path }] }
|
||||
else if (errorData.errors) {
|
||||
const emailError = errorData.errors.find(e => e.path === 'email');
|
||||
|
||||
// Extract suggested email from "Did you mean user@gmail.com?" message
|
||||
const suggestionMatch = emailError.msg.match(/Did you mean (.+)\?/);
|
||||
if (suggestionMatch) {
|
||||
setSuggestedEmail(suggestionMatch[1]);
|
||||
if (emailError) {
|
||||
setError(emailError.msg);
|
||||
|
||||
// Extract suggested email from "Did you mean user@gmail.com?" message
|
||||
const suggestionMatch = emailError.msg.match(/Did you mean (.+)\?/);
|
||||
if (suggestionMatch) {
|
||||
setSuggestedEmail(suggestionMatch[1]);
|
||||
} else {
|
||||
setSuggestedEmail(null);
|
||||
}
|
||||
} else {
|
||||
setError(errorData.errors[0]?.msg || 'Email validation failed');
|
||||
setSuggestedEmail(null);
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user