diff --git a/app/services/api/src/finquest_api/config.py b/app/services/api/src/finquest_api/config.py index 0f44ad4..f08fc32 100644 --- a/app/services/api/src/finquest_api/config.py +++ b/app/services/api/src/finquest_api/config.py @@ -31,12 +31,18 @@ class Settings(BaseSettings): API_VERSION: str = "0.1.0" DEBUG: bool = True - # CORS Configuration - ALLOWED_ORIGINS: List[str] = [ - "http://localhost:3000", - "http://localhost:3001", - "http://127.0.0.1:3000", - ] + # CORS Configuration - stored as string, converted to list via property + ALLOWED_ORIGINS: str = "http://localhost:3000,http://localhost:3001,http://127.0.0.1:3000,https://tryfinquest.vercel.app" + + @property + def allowed_origins_list(self) -> List[str]: + """Parse CORS origins from comma-separated string to list""" + if not self.ALLOWED_ORIGINS: + return [] + # Split by comma and strip whitespace, remove empty strings + origins = [origin.strip() for origin in self.ALLOWED_ORIGINS.split(",") if origin.strip()] + # Remove trailing slashes for consistency + return [origin.rstrip("/") for origin in origins] # Server Configuration HOST: str = "0.0.0.0" diff --git a/app/services/api/src/finquest_api/main.py b/app/services/api/src/finquest_api/main.py index c3d2403..b9b0f67 100644 --- a/app/services/api/src/finquest_api/main.py +++ b/app/services/api/src/finquest_api/main.py @@ -19,7 +19,7 @@ # Configure CORS app.add_middleware( CORSMiddleware, - allow_origins=settings.ALLOWED_ORIGINS, + allow_origins=settings.allowed_origins_list, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], diff --git a/app/services/api/src/finquest_api/routers/users.py b/app/services/api/src/finquest_api/routers/users.py index 914edb5..8f3f366 100644 --- a/app/services/api/src/finquest_api/routers/users.py +++ b/app/services/api/src/finquest_api/routers/users.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import Session from ..auth_utils import get_current_user from ..db.models import User, OnboardingResponse, Suggestion -from ..db.session import get_session, SessionLocal +from ..db.session import get_session, SessionLocal, get_engine from ..schemas import UpdateProfileRequest, SuggestionResponse from ..services.llm.service import LLMService from ..services.module_generator import ModuleGenerator @@ -26,7 +26,7 @@ async def generate_suggestions_task( user_id: str ): """Background task to generate suggestions""" - db = SessionLocal() + db = SessionLocal(bind=get_engine()) try: user = db.query(User).filter(User.id == user_id).first() if user: diff --git a/app/web/.env.example b/app/web/.env.example index a32ea68..4163e4e 100644 --- a/app/web/.env.example +++ b/app/web/.env.example @@ -1,3 +1,4 @@ NEXT_PUBLIC_SUPABASE_URL=url NEXT_PUBLIC_SUPABASE_ANON_KEY=key -NEXT_PUBLIC_API_URL=http://localhost:8000 \ No newline at end of file +NEXT_PUBLIC_API_URL=http://localhost:8000 +NEXT_PUBLIC_SITE_URL=http://localhost:3000 \ No newline at end of file diff --git a/app/web/README.md b/app/web/README.md index 802b4df..af2b1ee 100644 --- a/app/web/README.md +++ b/app/web/README.md @@ -10,6 +10,37 @@ Install dependencies: pnpm install ``` +### Environment Variables + +Create a `.env.local` file in the `app/web/` directory with the following variables: + +```bash +# Supabase Configuration (required) +NEXT_PUBLIC_SUPABASE_URL=your_supabase_url +NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key + +# API Configuration (optional - defaults to http://localhost:8000 for local dev) +NEXT_PUBLIC_API_URL=http://localhost:8000 +``` + +**For Production (e.g., Vercel):** + +- Set `NEXT_PUBLIC_API_URL` to `https://finquest-api.onrender.com` +- The API URL automatically switches based on the environment variable + +### Supabase OAuth Configuration + +For Google OAuth to work correctly in both development and production, you need to configure redirect URLs in your Supabase dashboard: + +1. Go to your Supabase project dashboard +2. Navigate to **Authentication** → **URL Configuration** +3. Add the following to **Redirect URLs**: + - `http://localhost:3000/` (for local development) + - `https://your-production-domain.com/` (for production) +4. Set the **Site URL** to your production URL (or leave it as default) + +**Important:** If localhost URLs are not whitelisted in Supabase, OAuth redirects will default to the Site URL, causing redirects to production even when running locally. + Then, run the development server: ````bash diff --git a/app/web/contexts/AuthContext.tsx b/app/web/contexts/AuthContext.tsx index b58367b..096a313 100644 --- a/app/web/contexts/AuthContext.tsx +++ b/app/web/contexts/AuthContext.tsx @@ -72,7 +72,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { const { error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { - redirectTo: `${window.location.origin}/`, + redirectTo: process.env.NEXT_PUBLIC_SITE_URL, }, }); diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..e8111e6 --- /dev/null +++ b/render.yaml @@ -0,0 +1,42 @@ +services: + - type: web + name: finquest-api + runtime: python + plan: free + buildCommand: cd app/services/api && pip install uv && uv python install 3.9 && uv python pin 3.9 && uv sync + startCommand: cd app/services/api && uv run uvicorn finquest_api.main:app --host 0.0.0.0 --port $PORT + envVars: + - key: PYTHON_VERSION + value: 3.9.0 + - key: PORT + value: 8000 + - key: UV_PYTHON_DOWNLOADS + value: manual + # Supabase Configuration - Set these in Render dashboard + - key: SUPABASE_URL + sync: false + - key: SUPABASE_KEY + sync: false + - key: SUPABASE_JWT_SECRET + sync: false + - key: SUPABASE_DB_URL + sync: false + # LLM Configuration - Set these in Render dashboard + - key: LLM_PROVIDER + value: gemini + - key: LLM_BASE_URL + value: https://generativelanguage.googleapis.com/v1beta + - key: LLM_MODEL + value: gemini-2.0-flash + - key: LLM_API_KEY + sync: false + - key: LLM_ORG_ID + sync: false + - key: LLM_TIMEOUT_SECONDS + value: 30.0 + - key: LLM_MAX_RETRIES + value: 2 + # CORS Configuration - Update with your frontend URL + - key: ALLOWED_ORIGINS + value: http://localhost:3000,http://localhost:3001,http://127.0.0.1:3000,https://tryfinquest.vercel.app +