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