# 🔧 Quick Fix: Redirect URI Mismatch Error

## The Problem
You're seeing: **"Error 400: redirect_uri_mismatch"**

This means the callback URL in your code doesn't match what's configured in Google Cloud Console.

## ✅ Solution (5 Steps)

### Step 1: Check Your Current Configuration
Visit this URL in your browser (while your backend is running):
```
http://localhost:4000/auth/google/debug
```

This shows you the exact callback URL your code is using.

### Step 2: Check Your .env File
Open `Backend/.env` and verify:
```env
BACKEND_URL=http://localhost:4000
GOOGLE_OAUTH_CLIENT_ID=your_actual_client_id
GOOGLE_OAUTH_CLIENT_SECRET=your_actual_client_secret
```

### Step 3: Fix Google Cloud Console

1. Go to: https://console.cloud.google.com/apis/credentials
2. Click on your **OAuth 2.0 Client ID**
3. Scroll to **Authorized redirect URIs**
4. **Add or edit** the redirect URI to match EXACTLY:
   ```
   http://localhost:4000/auth/google/callback
   ```

   ⚠️ **MUST BE EXACT:**
   - ✅ `http://localhost:4000/auth/google/callback` (CORRECT)
   - ❌ `http://localhost:4000/auth/google/callback/` (NO trailing slash)
   - ❌ `https://localhost:4000/auth/google/callback` (NO https)
   - ❌ `http://127.0.0.1:4000/auth/google/callback` (NO 127.0.0.1)

5. Click **SAVE**

### Step 4: Restart Your Backend Server
```bash
# Stop the server (Ctrl+C)
cd Backend
npm run dev
```

Look for the console output that shows:
```
🔐 Google OAuth Configuration:
   Callback URL: http://localhost:4000/auth/google/callback
```

### Step 5: Test Again
1. Clear your browser cache or use Incognito mode
2. Try logging in with Google again

## 🐛 Still Not Working?

### Check the Server Logs
When you start the server, you should see:
```
🔐 Google OAuth Configuration:
   Client ID: ✓ Set
   Client Secret: ✓ Set
   Callback URL: http://localhost:4000/auth/google/callback
```

If you see "✗ Missing" for Client ID or Secret, your `.env` file is not being loaded.

### Verify Environment Variables
Make sure your `.env` file is in the `Backend/` directory (same level as `package.json`).

### Common Issues

**Issue:** "Client ID: ✗ Missing"
- **Fix:** Check that `GOOGLE_OAUTH_CLIENT_ID` is in your `.env` file

**Issue:** "Callback URL: undefined/auth/google/callback"
- **Fix:** Add `BACKEND_URL=http://localhost:4000` to your `.env` file

**Issue:** Still getting mismatch error after fixing
- **Fix:** Wait 1-2 minutes for Google's cache to clear, or try incognito mode

## 📋 Checklist

- [ ] `.env` file exists in `Backend/` directory
- [ ] `BACKEND_URL=http://localhost:4000` in `.env`
- [ ] `GOOGLE_OAUTH_CLIENT_ID` and `GOOGLE_OAUTH_CLIENT_SECRET` in `.env`
- [ ] Google Console has EXACT redirect URI: `http://localhost:4000/auth/google/callback`
- [ ] Server restarted after changes
- [ ] Server logs show correct callback URL
- [ ] Tried in incognito/private browsing mode

