fix(cms): restore auth: false on custom REST endpoints#647
Merged
Conversation
|
🚅 Deployed to the forge-pr-647 environment in forge
2 services not affected by this PR
|
Strapi v5 custom routes with auth: false bypass all auth, but removing auth: false enables Users & Permissions (which needs admin-configured roles, not API tokens) — causing 404s. Solution: keep auth: false to bypass U&P, add a global api-token-auth middleware that validates the Bearer token against Strapi's hashed API token store. Applied to both language-geo and video-coverage endpoints. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2cc466f to
4dc9839
Compare
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
Hotfix — PR #646 removed
auth: falsefrom custom routes, causing a 404 on/api/language-geoin production. Strapi v5 custom routes withoutauth: falsefall under Users & Permissions, which requires admin-configured roles — not API token auth.Fix: Created a global
api-token-authmiddleware that validates the Bearer token against Strapi's hashed API token store. Routes keepauth: false(to bypass U&P) but add the middleware for real auth:Applied to both
language-geoandvideo-coverageendpoints.How it works
Authorization: Bearer <token>headerapiTokenService.hash)admin::api-tokentable viaapiTokenService.getBynext()if validFiles
apps/cms/src/middlewares/api-token-auth.ts— global middlewareapps/cms/src/api/language-geo/routes/language-geo.ts— adds middlewareapps/cms/src/api/video-coverage/routes/video-coverage.ts— adds middlewareTesting