Skip to content

Commit 290d6db

Browse files
committed
refactor(auth): migrate /api/repos routes to unified auth
- GET /api/repos now uses require_auth + AuthContext - POST /api/repos now uses require_auth + AuthContext - Supports both JWT and API key authentication Part of #12
1 parent 3225a05 commit 290d6db

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

backend/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Import routers
2929
from routes.auth import router as auth_router
30-
from middleware.auth import get_current_user
30+
from middleware.auth import require_auth, AuthContext
3131

3232
app = FastAPI(
3333
title="CodeIntel API",
@@ -144,9 +144,9 @@ async def health_check():
144144

145145

146146
@app.get("/api/repos")
147-
async def list_repositories(current_user: dict = Depends(get_current_user)):
147+
async def list_repositories(auth: AuthContext = Depends(require_auth)):
148148
"""List all repositories for authenticated user"""
149-
user_id = current_user["user_id"]
149+
user_id = auth.user_id
150150

151151
# TODO: Filter repos by user_id once we add user_id column to repositories table
152152
# For now, return all repos (will fix in next section)
@@ -157,10 +157,10 @@ async def list_repositories(current_user: dict = Depends(get_current_user)):
157157
@app.post("/api/repos")
158158
async def add_repository(
159159
request: AddRepoRequest,
160-
current_user: dict = Depends(get_current_user)
160+
auth: AuthContext = Depends(require_auth)
161161
):
162162
"""Add a new repository with validation and cost controls"""
163-
user_id = current_user["user_id"]
163+
user_id = auth.user_id or auth.identifier
164164

165165
# Validate repository name
166166
valid_name, name_error = InputValidator.validate_repo_name(request.name)

0 commit comments

Comments
 (0)