Skip to content

Commit 40dc05f

Browse files
committed
/auth/login and /auth/refresh should not be relative the app URL.
1 parent 3a8a089 commit 40dc05f

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

client/src/App.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function App() {
7878

7979
// If unauthorized, try to refresh the token
8080
if (userRes.status === 401) {
81-
const refreshRes = await fetch(buildApiPath("/auth/refresh"), {
81+
const refreshRes = await fetch("/auth/refresh", {
8282
credentials: "include",
8383
});
8484

@@ -213,9 +213,7 @@ function App() {
213213
type="button"
214214
onClick={() => {
215215
const currentPage = encodeURIComponent(window.location.href);
216-
window.location.href = buildApiPath(
217-
`/auth/login?redirect_uri=${currentPage}`
218-
);
216+
window.location.href = `/auth/login?redirect_uri=${currentPage}`;
219217
}}
220218
style={{
221219
padding: "10px 20px",

client/vite.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export default defineConfig(({ command }) => ({
2222
target: 'http://127.0.0.1:8000', // Your FastAPI backend
2323
changeOrigin: true,
2424
},
25+
'/auth': {
26+
target: 'http://127.0.0.1:8000', // Your FastAPI backend
27+
changeOrigin: true,
28+
},
2529
},
2630
},
2731
}))

pyapp/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
auth_api.py

pyapp/app/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from pathlib import Path
21
from contextlib import asynccontextmanager
2+
from pathlib import Path
33

44
from fastapi import FastAPI, HTTPException, Request, status
55
from fastapi.responses import FileResponse
66
from fastapi.staticfiles import StaticFiles
77
from fastapi.templating import Jinja2Templates
8-
from starlette.middleware.sessions import SessionMiddleware
98
from prometheus_fastapi_instrumentator import Instrumentator
9+
from starlette.middleware.sessions import SessionMiddleware
1010

1111
from .config import get_settings
1212
from .info_api import router as info_router
1313

14-
1514
# Create an instrumentor object
1615
instrumentator = Instrumentator()
1716

@@ -65,6 +64,11 @@ async def serve_react_app(request: Request, full_path: str):
6564
else:
6665
return FileResponse(str(file_path))
6766

67+
else: # We are running in dev
68+
from .auth_api import auth_router
69+
70+
app.include_router(auth_router, include_in_schema=False) # We need the '/auth' API
71+
6872

6973
# Add a root endpoint for basic API health check
7074
@app.get("/", include_in_schema=False)

0 commit comments

Comments
 (0)