File size: 4,925 Bytes
a0088ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Firebase Setup Guide

## Firebase Project Information

**Project ID:** `colorize-662df`  
**Credentials File:** `colorize-662df-firebase-adminsdk-fbsvc-bfd21c77c6.json`

## Required Firebase Configuration

### 1. Firebase Admin SDK Credentials ✅
The credentials file is already in the project:
- File: `colorize-662df-firebase-adminsdk-fbsvc-bfd21c77c6.json`
- The application will automatically detect and use this file

### 2. Firebase Web API Key (Required for Login/Register)

To get your Firebase Web API Key:

1. Go to [Firebase Console](https://console.firebase.google.com/)
2. Select your project: **colorize-662df**
3. Click the gear icon ⚙️ → **Project settings**
4. Scroll down to **Your apps** section
5. Find the **Web API Key** (starts with `AIza...`)
6. Copy this key

**Set it as environment variable:**
```bash
export FIREBASE_API_KEY="AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68"
```

Or in Hugging Face Spaces:
- Go to Settings → Secrets
- Add secret: `FIREBASE_API_KEY` = `AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68`

### 3. Firebase App Check Configuration

For App Check to work, you need:

1. **Enable App Check in Firebase Console:**
   - Go to Firebase Console → **App Check**
   - Register your app
   - Choose **reCAPTCHA Enterprise** provider
   - Get your **reCAPTCHA Site Key**

2. **Frontend Setup:**
   ```javascript
   import { initializeApp } from "firebase/app";
   import { initializeAppCheck, ReCaptchaEnterpriseProvider, getToken } from "firebase/app-check";

   const firebaseConfig = {
     apiKey: "AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68",
     authDomain: "colorize-662df.firebaseapp.com",
     projectId: "colorize-662df",
     storageBucket: "colorize-662df.firebasestorage.app",
     messagingSenderId: "69166278311",
     appId: "1:69166278311:web:0e8c50b8dd8627aaeadd82",
     measurementId: "G-58CC2J8XKX"
   };

   const app = initializeApp(firebaseConfig);

   const appCheck = initializeAppCheck(app, {
     provider: new ReCaptchaEnterpriseProvider('YOUR_RECAPTCHA_SITE_KEY'),
     isTokenAutoRefreshEnabled: true
   });

   // Get token for API requests
   const token = await getToken(appCheck);
   ```

## Environment Variables

### For Local Development:
```bash
# Firebase credentials (optional if file is in project root)
export FIREBASE_CREDENTIALS_PATH="./colorize-662df-firebase-adminsdk-fbsvc-bfd21c77c6.json"

# Firebase Web API Key (required for /auth/login and /auth/register)
export FIREBASE_API_KEY="AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68"

# Optional: Disable auth for testing
export DISABLE_AUTH="false"

# Optional: Disable App Check
export ENABLE_APP_CHECK="true"
```

### For Hugging Face Spaces:
Add these as **Secrets** in Space Settings:

1. **FIREBASE_CREDENTIALS** - Paste the entire contents of `colorize-662df-firebase-adminsdk-fbsvc-bfd21c77c6.json`
2. **FIREBASE_API_KEY** - Your Web API Key (`AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68`)
3. **HF_TOKEN** - Your Hugging Face token (for Inference API)

## Testing Firebase Connection

### Test 1: Health Check (No Auth Required)
```bash
curl https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/health
```

### Test 2: Register User (Requires FIREBASE_API_KEY)
```bash
curl -X POST https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "password123",
    "display_name": "Test User"
  }'
```

### Test 3: Login (Requires FIREBASE_API_KEY)
```bash
curl -X POST https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "password123"
  }'
```

### Test 4: Colorize with App Check Token
```bash
curl -X POST https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize \
  -H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
  -F "file=@image.jpg"
```

## Troubleshooting

### Issue: "Firebase not initialized"
**Solution:** Make sure the credentials file exists and is readable

### Issue: "Firebase API key not configured" (for login/register)
**Solution:** Set `FIREBASE_API_KEY` environment variable

### Issue: "Invalid App Check token"
**Solution:** 
1. Make sure App Check is enabled in Firebase Console
2. Verify you're sending the token in `X-Firebase-AppCheck` header
3. Check that reCAPTCHA Enterprise is properly configured

### Issue: "Missing App Check token"
**Solution:** 
- Either provide `X-Firebase-AppCheck` header
- Or set `ENABLE_APP_CHECK=false` to disable (not recommended for production)

## Current Firebase Config

Based on your credentials file:
- **Project ID:** `colorize-662df`
- **Service Account:** `firebase-adminsdk-fbsvc@colorize-662df.iam.gserviceaccount.com`
- **Auth Domain:** `colorize-662df.firebaseapp.com`
- **Storage Bucket:** `colorize-662df.firebasestorage.app`