Skip to content

Commit 1f1c799

Browse files
jonstrutz11zacps
authored andcommitted
Allow APP_BASE to be an empty string when setting cookies
- I originally set APP_BASE to '/' instead of '' because setting cookies requires the slash and I wanted to reuse the APP_BASE env var when setting cookies - However, this seems to cause problems with svelte which doesn't allow APP_BASE to end in a slash (even if it's just a single slash): see https://svelte.dev/docs/kit/configuration#paths - Changed the logic so that APP_BASE can be '' if desired and when setting cookies, we just set the path to '/' if APP_BASE is ''
1 parent 9935f4f commit 1f1c799

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ADMIN_API_SECRET=# secret to admin API calls, like computing usage stats or expo
180180
# These values cannot be updated at runtime
181181
# They need to be passed when building the docker image
182182
# See https://github.com/huggingface/chat-ui/main/.github/workflows/deploy-prod.yml#L44-L47
183-
APP_BASE="/" # base path of the app, e.g. /chat
183+
APP_BASE= # base path of the app, e.g. /chat
184184
PUBLIC_APP_COLOR=blue # can be any of tailwind colors: https://tailwindcss.com/docs/customizing-colors#default-color-palette
185185
### Body size limit for SvelteKit https://svelte.dev/docs/kit/adapter-node#Environment-variables-BODY_SIZE_LIMIT
186186
BODY_SIZE_LIMIT=15728640

src/lib/server/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export async function logout(cookies: Cookies, locals: App.Locals) {
211211

212212
for (const cookie_name of cookie_names) {
213213
cookies.delete(cookie_name, {
214-
path: env.APP_BASE,
214+
path: env.APP_BASE || "/",
215215
// So that it works inside the space's iframe
216216
sameSite: dev || env.ALLOW_INSECURE_COOKIES === "true" ? "lax" : "none",
217217
secure: !dev && !(env.ALLOW_INSECURE_COOKIES === "true"),

src/lib/server/providers/microsoft_entra/providerEntra.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function getAccessToken(
5959
};
6060

6161
cookies.set(ProviderCookieNames.ACCESS_TOKEN, JSON.stringify(accessToken), {
62-
path: env.APP_BASE,
62+
path: env.APP_BASE || "/",
6363
// So that it works inside the space's iframe
6464
sameSite: dev || env.ALLOW_INSECURE_COOKIES === "true" ? "lax" : "none",
6565
secure: !dev && !(env.ALLOW_INSECURE_COOKIES === "true"),
@@ -68,7 +68,7 @@ async function getAccessToken(
6868
});
6969

7070
cookies.set(ProviderCookieNames.PROVIDER_PARAMS, JSON.stringify(newProviderParameters), {
71-
path: env.APP_BASE,
71+
path: env.APP_BASE || "/",
7272
// So that it works inside the space's iframe
7373
sameSite: dev || env.ALLOW_INSECURE_COOKIES === "true" ? "lax" : "none",
7474
secure: !dev && !(env.ALLOW_INSECURE_COOKIES === "true"),
@@ -109,7 +109,7 @@ async function refreshMicrosoftGraphToken(
109109
};
110110

111111
cookies.set(ProviderCookieNames.ACCESS_TOKEN, JSON.stringify(refreshedAccessToken), {
112-
path: env.APP_BASE,
112+
path: env.APP_BASE || "/",
113113
// So that it works inside the space's iframe
114114
sameSite: dev || env.ALLOW_INSECURE_COOKIES === "true" ? "lax" : "none",
115115
secure: !dev && !(env.ALLOW_INSECURE_COOKIES === "true"),

src/routes/login/callback/+server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function handleLogin(requestEvent: RequestEvent) {
8989
httpOnly: true,
9090
secure: true,
9191
sameSite: "none",
92-
path: env.APP_BASE,
92+
path: env.APP_BASE || "/",
9393
}
9494
);
9595
}

0 commit comments

Comments
 (0)