> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Braian551/viax/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify Email

> Check if a user account exists for an email address

## Endpoint

```
POST /auth/check_user.php
```

Verify whether a user account exists for the given email address. Useful for checking if an email is already registered before attempting registration.

## Headers

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

<ParamField header="Accept" type="string" required>
  Must be `application/json`
</ParamField>

## Request Body

<ParamField body="email" type="string" required>
  Email address to check
</ParamField>

## Response

<ResponseField name="exists" type="boolean" required>
  `true` if a user with this email exists, `false` otherwise
</ResponseField>

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://76.13.114.194/auth/check_user.php \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{
      "email": "carlos.rodriguez@example.com"
    }'
  ```

  ```dart Dart theme={null}
  import 'package:http/http.dart' as http;
  import 'dart:convert';

  Future<bool> checkEmailExists(String email) async {
    try {
      final response = await http.post(
        Uri.parse('https://76.13.114.194/auth/check_user.php'),
        headers: {
          'Content-Type': 'application/json',
          'Accept': 'application/json',
        },
        body: jsonEncode({'email': email}),
      ).timeout(Duration(seconds: 10));

      if (response.statusCode == 200) {
        final data = jsonDecode(response.body);
        return data['exists'] == true;
      }
      return false;
    } catch (e) {
      return false; // Assume doesn't exist on error
    }
  }
  ```

  ```javascript JavaScript theme={null}
  async function checkEmailExists(email) {
    try {
      const response = await fetch('https://76.13.114.194/auth/check_user.php', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Accept': 'application/json',
        },
        body: JSON.stringify({ email }),
      });
      
      const data = await response.json();
      return data.exists === true;
    } catch (error) {
      return false;
    }
  }
  ```
</CodeGroup>

## Response Example

<CodeGroup>
  ```json User Exists theme={null}
  {
    "exists": true
  }
  ```

  ```json User Does Not Exist theme={null}
  {
    "exists": false
  }
  ```
</CodeGroup>

## Use Cases

### Pre-Registration Validation

Check if an email is available before showing the registration form:

```dart theme={null}
Future<void> validateEmail(String email) async {
  final exists = await checkEmailExists(email);
  
  if (exists) {
    showError('Este email ya está registrado. ¿Desea iniciar sesión?');
    // Show login option
  } else {
    // Proceed with registration
    navigateToRegistrationForm(email);
  }
}
```

### Forgot Password Flow

Verify the email exists before sending a password reset:

```javascript theme={null}
async function initiatePasswordReset(email) {
  const exists = await checkEmailExists(email);
  
  if (!exists) {
    alert('No hay cuenta asociada con este email');
    return;
  }
  
  // Send password reset email
  await sendPasswordResetEmail(email);
}
```

### Smart Login/Register

Determine whether to show login or registration:

```dart theme={null}
Future<void> handleEmailSubmit(String email) async {
  final exists = await checkEmailExists(email);
  
  if (exists) {
    // Show password field for login
    setState(() {
      showPasswordField = true;
      isLoginMode = true;
    });
  } else {
    // Navigate to registration
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => RegisterScreen(email: email),
      ),
    );
  }
}
```

## Error Handling

<Note>
  This endpoint returns `{"exists": false}` on any error or if the request times out. This prevents exposing information about whether emails exist in the database during error conditions.
</Note>

```dart theme={null}
Future<Map<String, dynamic>> checkUserExists(String email) async {
  try {
    final response = await client.post(
      Uri.parse('$_baseUrl/check_user.php'),
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      },
      body: jsonEncode({'email': email}),
    ).timeout(AppConfig.connectionTimeout);

    if (response.statusCode == 200) {
      return jsonDecode(response.body) as Map<String, dynamic>;
    }

    return {'exists': false};
  } catch (e) {
    return {'exists': false};
  }
}
```

## Security Considerations

<Warning>
  This endpoint can be used to enumerate registered email addresses. In a production environment, consider:

  * Rate limiting to prevent abuse
  * CAPTCHA for repeated checks
  * Logging suspicious activity
  * Generic error messages that don't reveal user existence
</Warning>

## See Also

* [Register](/api/auth/register) - Create a new user account
* [Login](/api/auth/login) - Authenticate an existing user
* [User Profile](/api/users/profile) - Get user information
