Skip to content

Commit c0b51c0

Browse files
Clément VALENTINclaude
andcommitted
fix(auth): preserve query params in OAuth callback redirect
When an unauthenticated user landed on /oauth/callback?code=..., the ProtectedRoute component was only saving location.pathname in the redirect state, losing the query parameters. After login, the user was redirected to /oauth/callback without the code parameter, causing "Paramètres de callback invalides" error. Changes: - ProtectedRoute now saves pathname + search in redirect state - Added Vite proxy for /api/* to enable same-origin httpOnly cookies - Mount .env.web in frontend container for runtime env configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 90ef1a0 commit c0b51c0

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

apps/web/src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ function ProtectedRoute({ children }: { children: React.ReactNode }) {
6161
}
6262

6363
if (!isAuthenticated) {
64-
// Sauvegarder l'URL courante pour y revenir après connexion
65-
return <Navigate to="/login" state={{ from: location.pathname }} replace />
64+
// Sauvegarder l'URL courante (avec query params) pour y revenir après connexion
65+
const fullPath = location.pathname + location.search
66+
return <Navigate to="/login" state={{ from: fullPath }} replace />
6667
}
6768

6869
return <>{children}</>

apps/web/vite.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const __dirname = dirname(__filename)
88

99
export default defineConfig(({ mode }) => {
1010
const env = loadEnv(mode, process.cwd(), '')
11-
const backendUrl = env.VITE_BACKEND_URL || 'http://127.0.0.1:8000'
11+
// Use process.env first (from Docker env_file), then loadEnv, then default
12+
const backendUrl = process.env.VITE_BACKEND_URL || env.VITE_BACKEND_URL || 'http://backend:8000'
1213

1314
return {
1415
plugins: [react()],
@@ -75,6 +76,16 @@ export default defineConfig(({ mode }) => {
7576
hmr: {
7677
clientPort: 8000,
7778
},
79+
// Proxy API requests to backend - ensures same-origin for httpOnly cookies
80+
proxy: {
81+
'/api': {
82+
target: backendUrl,
83+
changeOrigin: true,
84+
rewrite: (path) => path.replace(/^\/api/, ''),
85+
// Forward cookies
86+
cookieDomainRewrite: 'localhost',
87+
},
88+
},
7889
},
7990
test: {
8091
globals: true,

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ services:
104104
- ./apps/web/tsconfig.node.json:/app/tsconfig.node.json
105105
- ./apps/web/tailwind.config.js:/app/tailwind.config.js
106106
- ./apps/web/postcss.config.js:/app/postcss.config.js
107+
- ./.env.web:/app/.env:ro
107108
- /app/node_modules
108109
ports:
109110
- "8000:5173"

0 commit comments

Comments
 (0)