> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ellipsi.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Common Issues

> Solutions for frequently encountered problems with database, authentication, and deployment.

## Database

<AccordionGroup>
  <Accordion title="Data going to the wrong database">
    **Symptom:** Users or watchlists are not showing up, or data appears in the `test` database instead of `SignalisticsDB`.

    **Cause:** The `MONGODB_URI` is missing the database name.

    **Fix:** Ensure your connection string includes `/SignalisticsDB?`:

    ```bash theme={null}
    # Correct
    mongodb+srv://user:pass@cluster.mongodb.net/SignalisticsDB?retryWrites=true&w=majority

    # Wrong
    mongodb+srv://user:pass@cluster.mongodb.net/?retryWrites=true&w=majority
    ```
  </Accordion>

  <Accordion title="Cannot connect to MongoDB in production">
    **Possible causes:**

    1. MongoDB Atlas is not allowing connections from Vercel's IPs — add `0.0.0.0/0` to the Atlas Network Access list
    2. Connection string credentials are incorrect
    3. Cluster is paused or unavailable

    **Verify your connection:**

    ```bash theme={null}
    npx tsx scripts/list-collections.ts
    ```
  </Accordion>

  <Accordion title="Migrating from 'test' to 'SignalisticsDB'">
    If you previously had data in the `test` database:

    1. Update `MONGODB_URI` to include `/SignalisticsDB?`
    2. Existing users will need to **re-register** (old accounts won't work)
    3. Use MongoDB Atlas UI or Compass to manually migrate any data you need to preserve
  </Accordion>
</AccordionGroup>

## Authentication

<AccordionGroup>
  <Accordion title="'Email not verified' error on sign-in">
    **Cause:** The user signed up but never verified their email, or the verification link was broken.

    **Fix:**

    1. Check if `BETTER_AUTH_URL` is correctly set to your production domain
    2. Verify the user's `emailVerified` field in MongoDB:

    ```javascript theme={null}
    db.user.findOne({ email: "user@example.com" })
    // Should show: emailVerified: true
    ```

    3. If `false`, the user needs to verify again — clear the user and have them re-register:

    ```bash theme={null}
    npx tsx scripts/clear-users.ts
    ```
  </Accordion>

  <Accordion title="Stale sessions or cookies">
    **Symptom:** Auth state is inconsistent, user appears logged in but gets errors.

    **Fix:**

    1. Clear browser cookies for your domain
    2. Try in incognito/private browsing
    3. Better Auth might have a stale session — clearing cookies forces a fresh login
  </Accordion>

  <Accordion title="Token appears invalid">
    **Possible causes:**

    * The token has expired (verification: 24h, magic link: 5min, password reset: 1h)
    * The link was already used (tokens are one-time use)
    * `BETTER_AUTH_SECRET` differs between environments

    **Fix:** Request a new token (re-send verification email, request new magic link, etc.)
  </Accordion>
</AccordionGroup>

## Deployment

<AccordionGroup>
  <Accordion title="Build fails on Vercel">
    **Common causes:**

    1. Missing environment variables — check all required variables are set
    2. TypeScript errors — run `npm run build` locally first
    3. Dependency issues — ensure `package-lock.json` is committed
  </Accordion>

  <Accordion title="Environment variables not taking effect">
    After updating variables in Vercel:

    1. Go to **Deployments** tab
    2. Click **...** on the latest deployment
    3. Select **Redeploy** — env var changes require a new deployment
  </Accordion>
</AccordionGroup>
