Skip to content

Commit 7546ba8

Browse files
authored
fix: navigate directly to Google authorize endpoints (#44)
`handleGoogleLogin` and the Google branch of `handleConnect` both called `api.get('.../authorize').json()` and then navigated to the returned `authorization_url`. In production the authorize endpoint returns a 302 to accounts.google.com, which Ky's fetch follows automatically — and the browser blocks the cross-origin call because accounts.google.com isn't in our CSP connect-src. Switch both to direct navigation (mirroring the existing Steam pattern in c8d1e2d). The browser navigates to the API, the API 302s, the browser follows the redirect — CSP connect-src doesn't apply to navigation. API code (app/routers/auth_providers.py) confirms login_authorize and associate_authorize share the same dev-JSON / prod-302 behavior across both providers, so this aligns Google with how Steam already works.
1 parent 58158a1 commit 7546ba8

2 files changed

Lines changed: 16 additions & 36 deletions

File tree

src/pages/login/login-page.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,19 @@ export function LoginPage() {
4444
}
4545
}
4646

47-
async function handleGoogleLogin() {
48-
try {
49-
if (redirect) localStorage.setItem("auth_redirect", redirect)
50-
const res = await api
51-
.get("auth/google/authorize")
52-
.json<{ authorization_url: string }>()
53-
window.location.href = res.authorization_url
54-
} catch (error) {
55-
const message = await getErrorMessage(
56-
error,
57-
"Failed to start Google sign-in"
58-
)
59-
toast.error(message)
60-
}
47+
function handleGoogleLogin() {
48+
if (redirect) localStorage.setItem("auth_redirect", redirect)
49+
// The authorize endpoint 302s to accounts.google.com in production.
50+
// Fetching it would follow the redirect via fetch, which the browser
51+
// blocks because accounts.google.com isn't in our CSP connect-src.
52+
// Direct navigation sidesteps connect-src entirely.
53+
window.location.href = `${baseUrl}/auth/google/authorize`
6154
}
6255

6356
function handleSteamLogin() {
6457
if (redirect) localStorage.setItem("auth_redirect", redirect)
65-
// In production, the authorize endpoint returns a 307 redirect to Steam,
66-
// so we navigate directly instead of fetching (avoids CSP issues).
58+
// Same reasoning as handleGoogleLogin: the authorize endpoint 307s to
59+
// Steam's OpenID, so we navigate directly to avoid a CSP-blocked fetch.
6760
window.location.href = `${baseUrl}/auth/steam/authorize`
6861
}
6962

src/pages/profile/profile-page.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,14 @@ export function ProfilePage() {
165165
}
166166
}
167167

168-
async function handleConnect(provider: ProviderId) {
168+
function handleConnect(provider: ProviderId) {
169169
setConnectingProvider(provider)
170-
try {
171-
if (provider === "steam") {
172-
// Steam's authorize endpoint 307s straight to Steam's OpenID; navigate
173-
// there directly to keep the redirect chain server-driven.
174-
window.location.href = `${baseUrl}/auth/steam/associate/authorize`
175-
return
176-
}
177-
const res = await api
178-
.get(`auth/${provider}/associate/authorize`)
179-
.json<{ authorization_url: string }>()
180-
window.location.href = res.authorization_url
181-
} catch (error) {
182-
const message = await getErrorMessage(
183-
error,
184-
`Failed to start linking ${provider}`
185-
)
186-
toast.error(message)
187-
setConnectingProvider(null)
188-
}
170+
// Both providers' associate-authorize endpoints 302 to the provider in
171+
// production. Fetching first would let the browser follow the redirect
172+
// via fetch — CSP connect-src blocks the cross-origin call to
173+
// accounts.google.com / steamcommunity.com. Direct navigation
174+
// sidesteps connect-src entirely.
175+
window.location.href = `${baseUrl}/auth/${provider}/associate/authorize`
189176
}
190177

191178
async function handleDisconnect(provider: ProviderId) {

0 commit comments

Comments
 (0)