fix: bypass auth middleware for REST API v1 and agent endpoints#48
Merged
TerrifiedBug merged 1 commit intomainfrom Mar 7, 2026
Merged
fix: bypass auth middleware for REST API v1 and agent endpoints#48TerrifiedBug merged 1 commit intomainfrom
TerrifiedBug merged 1 commit intomainfrom
Conversation
The Next.js auth middleware was intercepting /api/v1/* and /api/agent/* requests and redirecting them to /login before route handlers could process Bearer token authentication. This adds both paths to the middleware bypass list and restores the middleware.ts entry point (previously deleted) with the correct matcher exclusions.
Contributor
Greptile SummaryThis PR fixes a regression where Next.js auth middleware was issuing HTTP 307 redirects to Key observations:
Confidence Score: 4/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
REQ[Incoming Request] --> MATCHER{middleware.ts matcher\nexcludes api/v1, api/agent?}
MATCHER -- Yes, excluded --> HANDLER[Route Handler]
MATCHER -- No, runs middleware --> AUTH_CB{authorized callback\nin auth.config.ts}
AUTH_CB -- isApiV1 or isAgentApi --> HANDLER
AUTH_CB -- isAuthPage / isHealth / isSetupApi --> HANDLER
AUTH_CB -- not logged in --> LOGIN[Redirect to /login 307]
AUTH_CB -- logged in --> HANDLER
HANDLER --> API_V1{/api/v1/* ?}
HANDLER --> AGENT{/api/agent/* ?}
HANDLER --> OTHER[Other authenticated route]
API_V1 --> BEARER[authenticateApiKey\nBearer token check\n→ 401 if missing/invalid]
AGENT --> ENROLL_TOKEN[verifyEnrollmentToken\nor node Bearer token\n→ 401 if invalid]
Last reviewed commit: 00ad0c7 |
TerrifiedBug
added a commit
that referenced
this pull request
Mar 7, 2026
Next.js 16 replaced middleware.ts with proxy.ts. PR #48 reintroduced middleware.ts alongside the existing proxy.ts, causing the Docker build to fail with "Both middleware file and proxy file are detected". - Delete src/middleware.ts - Add api/v1 exclusion to proxy.ts matcher (was only in middleware.ts)
3 tasks
TerrifiedBug
added a commit
that referenced
this pull request
Mar 7, 2026
Next.js 16 replaced middleware.ts with proxy.ts. PR #48 reintroduced middleware.ts alongside the existing proxy.ts, causing the Docker build to fail with "Both middleware file and proxy file are detected". - Delete src/middleware.ts - Add api/v1 exclusion to proxy.ts matcher (was only in middleware.ts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/v1/*and/api/agent/*requests, redirecting them to/login(HTTP 307) before the route handlers could process Bearer token / enrollment token authenticationauthorizedcallback bypass inauth.config.tssrc/middleware.ts(previously deleted) with correct matcher exclusions forapi/v1andapi/agentTest plan
GET /api/v1/pipelineswith a service account Bearer token — should return JSON instead of 307 redirectGET /api/v1/nodes,/api/v1/secrets,/api/v1/alerts/rules,/api/v1/auditall work/api/v1/*return 401 (not 307 redirect)