# SDK Troubleshooting

This document provides solutions to common issues and frequently asked questions when integrating **ConnectFramework** in **Python, JavaScript, Swift, and Rust**.

***

### Common Issues and Solutions

#### Invalid API Key Error

**Cause:** Your API key is incorrect or missing.

**Solution:**

1. Ensure that you initialize the SDK with the correct API key:

   ```python
   ConnectFramework.initialize(api_key="your_api_key_here")
   ```

   ```javascript
   ConnectFramework.initialize("your_api_key_here");
   ```

   ```swift
   ConnectFramework.initialize(apiKey: "your_api_key_here")
   ```

   ```rust
   ConnectFramework::initialize("your_api_key_here");
   ```
2. Verify your API key in the **developer dashboard**.
3. Ensure your API key is **not expired or deactivated**.

***

#### Login Is Not Working or Returning `False`

**Possible Causes:**

* The API key might not have been initialized.
* The user email or unique ID is incorrect.
* OTP verification is required but has not been completed.

**Solution:**

1. Double-check that initialization occurs before calling `login()`:

   ```python
   ConnectFramework.initialize(api_key="your_api_key_here")
   ConnectFramework.login(unique_id=None, email="user@example.com", callback=login_callback)
   ```
2. Ensure the provided email is correct.
3. If OTP verification is required, submit the OTP:

   ```python
   ConnectFramework.submit_otp(email="user@example.com", otp_code="123456", callback=otp_callback)
   ```

***

#### OTP Verification Failing

**Possible Causes:**

* The OTP code is incorrect.
* The OTP has expired.

**Solution:**

1. Ensure the user enters the correct OTP.
2. If the OTP is expired, request a **new OTP** and retry.
3. Handle OTP expiration gracefully in the user interface.

***

#### Logout Is Not Working

**Possible Cause:** The function may not be called properly.

**Solution:**\
Ensure `logout()` is executed correctly:

```python
ConnectFramework.logout()
```

```javascript
ConnectFramework.logout();
```

```swift
ConnectFramework.logout()
```

```rust
ConnectFramework::logout();
```

If the problem persists, confirm if the user is currently logged in before calling `logout()`:

```python
if ConnectFramework.is_connected():
    ConnectFramework.logout()
```

***

#### `is_connected()` Returns `False` Even After Login

**Possible Cause:** The **Connect.ai desktop client** may not be running.

**Solution:**

1. Ensure that the **Connect.ai desktop client is installed and running**.
2. Verify if the user is actually logged in:

   ```python
   if ConnectFramework.is_connected():
       print("User is connected.")
   else:
       print("User is not connected. Please check the desktop client.")
   ```
3. Restart the desktop client and try again.

***

#### Analytics Events Are Not Showing Up

**Possible Causes:**

* Data processing delay (events may take a few minutes to appear).
* API key is incorrect.
* Network connectivity issues.

**Solution:**

1. Confirm that analytics events are being sent correctly:

   ```python
   ConnectFramework.log_event(category="user_action", action="button_click")
   ```
2. Check the **network connection**.
3. Wait a few minutes for events to appear in the **developer dashboard**.
4. Try submitting an event with additional details:

   ```python
   ConnectFramework.log_event_with_details(
       category="user_action",
       action="purchase",
       label="premium_upgrade",
       value=29.99
   )
   ```

***

### Frequently Asked Questions

#### Can I Use ConnectFramework Without an Email?

No. Email authentication is required for security and user verification.

***

#### Does ConnectFramework Support Multiple Logins at the Same Time?

No. Only one active session is allowed per user. If another login occurs, the previous session may be invalidated.

***

#### What Happens if the User Closes the OTP Verification Flow?

If the user does not complete OTP verification, they will not be logged in.\
You should handle this case in your user interface and allow the user to request a new OTP.

***

#### How Can I Check if a User Is Already Logged In?

Use `is_connected()` to check the login state:

```python
if ConnectFramework.is_connected():
    print("User is connected.")
else:
    print("User is not connected.")
```

***

#### How Do I Debug API Calls Failing in JavaScript?

If API requests fail in JavaScript, try the following:

1. Open the **Developer Console** (F12) and check the **Network** tab for errors.
2. Ensure the correct **API key** is set:

   ```javascript
   ConnectFramework.initialize("your_api_key_here");
   ```
3. Log errors to get more details:

   ```javascript
   ConnectFramework.login(null, "user@example.com", function(success) {
       if (!success) {
           console.error("Login failed. Check API settings.");
       }
   });
   ```

***

#### Does ConnectFramework Have an Offline Mode?

No. An internet connection is required for authentication and analytics tracking.

***

#### How Do I Reset a User Session Completely?

To reset a session:

1. Call `logout()`.
2. Restart the application.
3. Log in again.

***

#### How Do I Report an Issue with the SDK?

If you encounter any bugs or unexpected behavior:

* Check the **logs** for error messages.
* Verify your **API key, internet connection, and function parameters**.
* Contact **ConnectFramework Support** with error details and logs.

***

### Contact Support

If you're still experiencing issues, reach out to **<support@connect.ai>**
