From a5be0fba744ea466e6fd9e88253b9790021bf194 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Thu, 22 Jan 2026 16:22:26 +0100 Subject: [PATCH] refactor(oauth): improve URL construction in OAuth flow to prevent double slashes --- lib/api/oauth.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/api/oauth.ts b/lib/api/oauth.ts index 851856b..d3100de 100644 --- a/lib/api/oauth.ts +++ b/lib/api/oauth.ts @@ -50,7 +50,10 @@ export async function initiateOAuthFlow(redirectPath = '/auth/callback') { localStorage.setItem('oauth_state', state) localStorage.setItem('oauth_code_verifier', codeVerifier) - const redirectUri = encodeURIComponent(`${APP_URL}${redirectPath}`) + // * Ensure clean URL construction without double slashes + const baseUrl = APP_URL.endsWith('/') ? APP_URL.slice(0, -1) : APP_URL + const path = redirectPath.startsWith('/') ? redirectPath : `/${redirectPath}` + const redirectUri = encodeURIComponent(`${baseUrl}${path}`) const loginUrl = `${AUTH_URL}/login?client_id=pulse-app&redirect_uri=${redirectUri}&response_type=code&state=${state}&code_challenge=${codeChallenge}&code_challenge_method=S256` @@ -66,9 +69,12 @@ export async function initiateSignupFlow(redirectPath = '/auth/callback') { localStorage.setItem('oauth_state', state) localStorage.setItem('oauth_code_verifier', codeVerifier) - const redirectUri = encodeURIComponent(`${APP_URL}${redirectPath}`) + // * Ensure clean URL construction without double slashes + const baseUrl = APP_URL.endsWith('/') ? APP_URL.slice(0, -1) : APP_URL + const path = redirectPath.startsWith('/') ? redirectPath : `/${redirectPath}` + const redirectUri = encodeURIComponent(`${baseUrl}${path}`) const signupUrl = `${AUTH_URL}/signup?client_id=pulse-app&redirect_uri=${redirectUri}&response_type=code&state=${state}&code_challenge=${codeChallenge}&code_challenge_method=S256` window.location.href = signupUrl - } + } \ No newline at end of file