mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 11:22:49 -05:00
chore(devtools): pass debug auth token with server-side requests (#6836)
This commit is contained in:
1 parent
aa4b3d8a24
commit
4e7adcc9ee
4 files changed
+35
-16
No files matched your search
@@ -8,10 +8,6 @@ repos:
|
||||
# From: https://github.com/astral-sh/uv-pre-commit/pull/53/commits/d30b4298e4fb63ce8609e29acdbcf4c9018a483c
|
||||
rev: d30b4298e4fb63ce8609e29acdbcf4c9018a483c
|
||||
hooks:
|
||||
- id: uv-run
|
||||
name: Check lazy imports
|
||||
args: ["--with=onyx-devtools", "ods", "check-lazy-imports"]
|
||||
files: ^backend/(?!\.venv/).*\.py$
|
||||
- id: uv-sync
|
||||
args: ["--locked", "--all-extras"]
|
||||
- id: uv-lock
|
||||
@@ -32,6 +28,10 @@ repos:
|
||||
name: uv-export model_server.txt
|
||||
args: ["--no-emit-project", "--no-default-groups", "--no-hashes", "--extra", "model_server", "-o", "backend/requirements/model_server.txt"]
|
||||
files: ^(pyproject\.toml|uv\.lock|backend/requirements/.*\.txt)$
|
||||
- id: uv-run
|
||||
name: Check lazy imports
|
||||
args: ["--with=onyx-devtools", "ods", "check-lazy-imports"]
|
||||
files: ^backend/(?!\.venv/).*\.py$
|
||||
# NOTE: This takes ~6s on a single, large module which is prohibitively slow.
|
||||
# - id: uv-run
|
||||
# name: mypy
|
||||
|
||||
+4
-2
@@ -29,8 +29,7 @@ create a `.env.local` file in the `web/` directory with the following configurat
|
||||
|
||||
```text
|
||||
# Point local dev server to cloud backend
|
||||
# This allows testing frontend changes against the production/staging backend
|
||||
INTERNAL_URL=https://cloud.onyx.app/api
|
||||
INTERNAL_URL=https://st-dev.onyx.app/api
|
||||
|
||||
# Debug auth cookie for authenticating against remote backend
|
||||
# This cookie is automatically injected into API requests when in development mode
|
||||
@@ -43,6 +42,9 @@ INTERNAL_URL=https://cloud.onyx.app/api
|
||||
DEBUG_AUTH_COOKIE=your_cookie_value_here
|
||||
```
|
||||
|
||||
By default, this does _NOT_ override existing cookies, so if you've logged in previously, you
|
||||
may need to delete the cookies for the `localhost` domain.
|
||||
|
||||
**Important notes:**
|
||||
|
||||
- The `.env.local` file should be created in the `web/` directory (same level as `package.json`)
|
||||
|
||||
+19
-5
@@ -165,14 +165,13 @@ export const logoutSS = async (
|
||||
|
||||
export const getCurrentUserSS = async (): Promise<User | null> => {
|
||||
try {
|
||||
const cookieString = processCookies(await cookies());
|
||||
|
||||
const response = await fetch(buildUrl("/me"), {
|
||||
credentials: "include",
|
||||
next: { revalidate: 0 },
|
||||
headers: {
|
||||
cookie: (await cookies())
|
||||
.getAll()
|
||||
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||
.join("; "),
|
||||
cookie: cookieString,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -189,8 +188,23 @@ export const getCurrentUserSS = async (): Promise<User | null> => {
|
||||
};
|
||||
|
||||
export const processCookies = (cookies: ReadonlyRequestCookies): string => {
|
||||
return cookies
|
||||
let cookieString = cookies
|
||||
.getAll()
|
||||
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||
.join("; ");
|
||||
|
||||
// Inject debug auth cookie for local development against remote backend (only if not already present)
|
||||
if (process.env.DEBUG_AUTH_COOKIE && process.env.NODE_ENV === "development") {
|
||||
const hasAuthCookie = cookieString
|
||||
.split(/;\s*/)
|
||||
.some((c) => c.startsWith("fastapiusersauth="));
|
||||
if (!hasAuthCookie) {
|
||||
const debugCookie = `fastapiusersauth=${process.env.DEBUG_AUTH_COOKIE}`;
|
||||
cookieString = cookieString
|
||||
? `${cookieString}; ${debugCookie}`
|
||||
: debugCookie;
|
||||
}
|
||||
}
|
||||
|
||||
return cookieString;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { HOST_URL, INTERNAL_URL } from "./constants";
|
||||
import { processCookies } from "@/lib/userSS";
|
||||
|
||||
export function buildClientUrl(path: string) {
|
||||
if (path.startsWith("/")) {
|
||||
@@ -57,15 +58,17 @@ export class UrlBuilder {
|
||||
}
|
||||
|
||||
export async function fetchSS(url: string, options?: RequestInit) {
|
||||
const init = options || {
|
||||
const cookieString = processCookies(await cookies());
|
||||
|
||||
const init: RequestInit = {
|
||||
credentials: "include",
|
||||
cache: "no-store",
|
||||
...options,
|
||||
headers: {
|
||||
cookie: (await cookies())
|
||||
.getAll()
|
||||
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
||||
.join("; "),
|
||||
...options?.headers,
|
||||
cookie: cookieString,
|
||||
},
|
||||
};
|
||||
|
||||
return fetch(buildUrl(url), init);
|
||||
}
|
||||
Reference in new issue
Block a user