Skip to content

Commit b6aa12a

Browse files
committed
Allow /models and /api routes to be accessed without auth when AUTOMATIC_LOGIN is enabled
Previously, with AUTOMATIC_LOGIN=true, all routes except /login and /healthcheck would redirect to OAuth. This prevented unauthenticated access to the /models page and API endpoints like /api/models. This aligns the AUTOMATIC_LOGIN behavior with the regular login flow, which already excludes /models and /api routes from the OAuth redirect. Also fixes the /models/ pattern to /models (without trailing slash) so that the /models page itself is matched, not just /models/* subpages.
1 parent 999f616 commit b6aa12a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/hooks.server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ export const handle: Handle = async ({ event, resolve }) => {
145145

146146
if (loginEnabled && !auth.user && !event.url.pathname.startsWith(`${base}/.well-known/`)) {
147147
if (config.AUTOMATIC_LOGIN === "true") {
148-
// AUTOMATIC_LOGIN: always redirect to OAuth flow (unless already on login or healthcheck pages)
148+
// AUTOMATIC_LOGIN: always redirect to OAuth flow (unless already on login, healthcheck, models, or api pages)
149149
if (
150150
!event.url.pathname.startsWith(`${base}/login`) &&
151-
!event.url.pathname.startsWith(`${base}/healthcheck`)
151+
!event.url.pathname.startsWith(`${base}/healthcheck`) &&
152+
!event.url.pathname.startsWith(`${base}/models`) &&
153+
!event.url.pathname.startsWith(`${base}/api`)
152154
) {
153155
// To get the same CSRF token after callback
154156
refreshSessionCookie(event.cookies, auth.secretSessionId);
@@ -164,7 +166,7 @@ export const handle: Handle = async ({ event, resolve }) => {
164166
!event.url.pathname.startsWith(`${base}/healthcheck`) &&
165167
!event.url.pathname.startsWith(`${base}/r/`) &&
166168
!event.url.pathname.startsWith(`${base}/conversation/`) &&
167-
!event.url.pathname.startsWith(`${base}/models/`) &&
169+
!event.url.pathname.startsWith(`${base}/models`) &&
168170
!event.url.pathname.startsWith(`${base}/api`)
169171
) {
170172
refreshSessionCookie(event.cookies, auth.secretSessionId);

0 commit comments

Comments
 (0)