Skip to content

Commit 828b688

Browse files
committed
Fix Strava callback build-time Convex client initialization
1 parent 4fdfcd3 commit 828b688

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

.claude/napkin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
| 2026-02-13 | self | Used backticks inside a double-quoted `gh pr create --body` string, triggering shell command substitution and noisy side effects | Use a heredoc/file for PR body or avoid backticks in shell-quoted strings |
4141
## User Preferences
4242
- Always commit `.claude/napkin.md` with related task commits.
43+
- Avoid module-scope `new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!)` in route handlers; lazy-init inside request handlers with env guards to prevent build-time crashes.

apps/web/app/api/strava/callback/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { api } from "@repo/backend";
44

55
import { getServerAuth } from "@/lib/server-auth";
66

7-
const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
87
const STATE_COOKIE = "strava_oauth_state";
98
const DEFAULT_SUCCESS_URL = "/integrations?success=strava_connected";
109
const DEFAULT_ERROR_URL = "/integrations?error=strava_auth_failed";
@@ -38,6 +37,13 @@ interface StravaTokenResponse {
3837
}
3938

4039
export async function GET(request: NextRequest) {
40+
const convexUrl = process.env.NEXT_PUBLIC_CONVEX_URL;
41+
if (!convexUrl) {
42+
console.error("Missing NEXT_PUBLIC_CONVEX_URL for Strava callback route");
43+
return redirectWithCookieClear(request, DEFAULT_ERROR_URL, true);
44+
}
45+
const convex = new ConvexHttpClient(convexUrl);
46+
4147
const { userId, convexToken } = await getServerAuth();
4248

4349
if (!userId) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 2026-02-13 Fix Vercel build failure for Strava callback route
2+
3+
- [x] Identify build-time crash source in `/api/strava/callback`
4+
- [x] Prevent module-scope Convex client initialization without env vars
5+
- [x] Validate with typecheck

0 commit comments

Comments
 (0)