# Troubleshooting Guide - Gamze Shop & APK

## Issue 1: Admin Panel Not Opening (https://gamze.site.je/admin)

### Symptoms
- Admin panel shows blank page or keeps redirecting to login
- Cannot access `/admin` or `/admin?i=1`

### Solutions

#### Step 1: Check if database is initialized
1. Navigate to: `https://gamze.site.je/install.php`
2. Click "Install" button
3. If you see "Database setup complete", tables are ready
4. If error appears, check MySQL connection credentials in `config/config.php`

#### Step 2: Verify admin credentials
- **Default username:** `admin`
- **Default password:** `password`
- If changed, ask your admin to reset or update the password in database

#### Step 3: Check session configuration
- Admin panel requires cookies to be enabled in your browser
- Make sure you're using HTTPS (no HTTP)
- Try clearing cookies and logging in again

#### Step 4: Check database credentials
Edit `/config/config.php` and verify:
```php
'db' => [
    'host' => 'sql103.infinityfree.com',
    'port' => 3306,
    'name' => 'if0_41703087_beads_shop',
    'user' => 'if0_41703087',
    'pass' => 'elZ6SlAmDSFego',  // ← Must be correct
    'charset' => 'utf8mb4',
],
```

---

## Issue 2: APK App Cannot Login

### Symptoms
- Login button doesn't work or shows network error
- Error message like "Unauthorized" or "Connection failed"

### Cause
The APK was using HTTP but the site requires HTTPS. This has been fixed.

### Solutions

#### Option A: Rebuild APK (Recommended)
1. Open `android-app/` in Android Studio
2. Go to `Build → Build Bundle(s) / APK(s) → Build APK(s)`
3. Wait for build to complete
4. APK will be in: `android-app/app/build/outputs/apk/debug/app-debug.apk`
5. Install on your Android device
6. Try logging in with `admin` / `password`

#### Option B: Verify Current Settings
The following have been automatically updated:
- ✅ `ApiClient.kt` - BASE_URL changed to `https://gamze.site.je`
- ✅ `SessionInitializer.kt` - HTTPS cookies configured
- ✅ Server CORS headers enabled for cross-origin requests

#### Option C: Manual APK Configuration (if not rebuilding)
If you have an older APK built, manually update in Android:
1. Edit `android-app/app/src/main/java/uk/beads/manager/ApiClient.kt`
2. Change: `const val BASE_URL = "http://gamze.site.je"`
3. To: `const val BASE_URL = "https://gamze.site.je"`
4. Rebuild APK

### Firebase Setup (for notifications)
If app doesn't show order notifications:
1. Get FCM Server Key from Firebase Console
2. Update `config/config.php`:
```php
'firebase' => [
    'server_key' => 'YOUR_FCM_SERVER_KEY_HERE',
],
```

---

## Issue 3: CORS Errors (Mobile App)

The server now includes proper CORS headers to allow requests from any origin.

If you still see CORS errors:
1. Verify HTTPS is being used (not HTTP)
2. Check browser console for exact error
3. Make sure API endpoint is: `https://gamze.site.je/api/...`

---

## Testing the API Endpoints

### Test Login Endpoint
```bash
curl -X POST https://gamze.site.je/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"password"}'
```

Expected response:
```json
{
  "success": true,
  "token": "abc123xyz...",
  "user": {
    "id": 1,
    "name": "Shop Admin",
    "username": "admin"
  }
}
```

### Test Orders Endpoint (with token)
```bash
curl -X GET https://gamze.site.je/api/orders \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"
```

---

## Common Issues & Fixes

| Issue | Cause | Fix |
|-------|-------|-----|
| "Database connection error" | DB credentials wrong | Check `config/config.php` |
| Admin panel blank | Session not starting | Clear cookies, restart browser |
| APK login fails | HTTP instead of HTTPS | Rebuild APK with HTTPS URL |
| No order notifications | FCM not configured | Set Firebase server key in config |
| "Invalid CSRF token" | Form expired | Reload page and try again |

---

## Checking Your Server

### SSH/File Access Check
```bash
# Verify files exist
ls -la config/config.php
ls -la app/bootstrap.php
ls -la install.php

# Check PHP version (must be 8.1+)
php -v

# Test database connection
php -r "require 'app/bootstrap.php'; echo 'DB OK';"
```

---

## Getting Help

If issues persist:
1. Check error logs on your hosting (usually in cPanel)
2. Verify all files are uploaded correctly
3. Ensure database tables exist (run install.php)
4. Check that credentials in config.php are correct
5. Verify HTTPS is enabled on your domain

**For detailed debugging:** Check error logs and network requests using browser DevTools (F12 → Network/Console tabs).
