# 🚀 Quick Startup Guide

## Automated Startup (Recommended)

### Option 1: PowerShell (Easier)
```powershell
# Open PowerShell and run:
.\start_app.ps1
```

### Option 2: Command Prompt (Batch)
```cmd
start_app.bat
```

---

## Manual Startup (If Scripts Fail)

### Step 1: Start ngrok in one terminal
```powershell
ngrok http 5000
```

### Step 2: Sync credentials with current ngrok URL
```powershell
python update_ngrok_uri.py
```

### Step 3: Start Flask in another terminal
```powershell
python app.py
```

---

## What These Scripts Do

### `update_ngrok_uri.py`
- Detects the current ngrok public URL (from ngrok's local API)
- Updates `credentials.json` with the correct OAuth redirect URI
- Ensures Google OAuth login works with the current ngrok tunnel

### `start_app.ps1` or `start_app.bat`
- Automatically starts ngrok
- Waits 3 seconds for ngrok to initialize
- Runs `update_ngrok_uri.py` to sync credentials
- Starts Flask application
- Shows colored output for easy monitoring

---

## First Time Setup

1. **One-time Google OAuth Setup:**
   - Run `start_app.ps1`
   - Script will show the ngrok URL (e.g., `https://gawsy-gregg-overrudely.ngrok-free.dev`)
   - Add this URL to Google OAuth Console:
     - Go to: [Google Cloud Console](https://console.cloud.google.com/)
     - Find your OAuth 2.0 credential
     - Add redirect URI: `https://YOUR-NGROK-URL/oauth2callback`
     - Save

2. **After first setup, always use one of the startup scripts**
   - They automatically handle URL changes with ngrok

---

## Troubleshooting

### "ngrok not found" error
- Make sure ngrok is installed: `ngrok version`
- If not installed: Download from https://ngrok.com/download

### "Cannot connect to ngrok API" error
- ngrok may not be running yet
- Wait a few seconds and try again
- Or run `ngrok http 5000` manually first

### "credentials.json not found" error
- Download your Google OAuth credentials from Google Cloud Console
- Save as `credentials.json` in this folder

### OAuth login still fails
- Run the script again to update credentials
- Check ngrok URL matches what you added to Google OAuth Console

---

## How to Restart

If ngrok URL changes (it does every few days on free tier):

### Option A: Just re-run the startup script
```powershell
.\start_app.ps1
```
This automatically syncs the new URL.

### Option B: Manual sync
```powershell
python update_ngrok_uri.py  # Updates credentials.json
python app.py               # Restart Flask to use new URL
```

---

## Once the App is Running

Access it at: **https://YOUR-NGROK-URL** (shown in terminal output)

Example: `https://gawsy-gregg-overrudely.ngrok-free.dev`

---

## Tips

- Keep ngrok terminal visible to monitor tunnel status
- The script window can be minimized (ngrok runs in background)
- Flask terminal shows requests and errors in real-time
- If Flask crashes, just restart the script

---

## Still Having Issues?

1. Check ngrok is running: View ngrok web interface at `http://127.0.0.1:4040`
2. Check Flask is running: `curl http://localhost:5000` in PowerShell
3. Check credentials are current: Open `credentials.json` and verify the redirect URI
4. Restart completely:
   - Close all terminals
   - Run `start_app.ps1` again from fresh
