Skip to content

feat(auth): include token header for catalog search#1198

Draft
apetersson wants to merge 1 commit intowger-project:masterfrom
apetersson:apetersson/auth-only-catalog-endpoints
Draft

feat(auth): include token header for catalog search#1198
apetersson wants to merge 1 commit intowger-project:masterfrom
apetersson:apetersson/auth-only-catalog-endpoints

Conversation

@apetersson
Copy link

This PR sends auth headers for catalog search API calls that will be auth-required server-side.

note: This PR has been created with LLM assistance (codex). The change is not very big though, but necessary for my self-hosted resource protection to prevent DOS.

What changed

  • Add Authorization headers (via existing makeHeader()) to:
    • exercise translation search service
    • ingredient search service

Why

  • Prepares React client for backend change:
    • future wger PR: feat(api): require auth for public catalog endpoints
  • Prevents 403s after backend auth enforcement.

Compatibility

  • Backward compatible with current backend behavior:
    • authenticated requests already work
    • adding header does not break endpoints that still allow anonymous access
  • Safe to merge before backend PR.

Inter-dependency

  • Depends functionally on users being logged in once backend PR is live.
  • Should be merged/deployed before or together with backend auth-enforcement PR to avoid regressions in search UX.

I double-checked wger-flutter and for current app flow this should not break.

What I verified:

  • The app only loads main content after auth state is loggedIn:
    • main.dart
    • loggedOut shows login screen, not exercise/nutrition screens.
  • Catalog endpoints are called through WgerBaseProvider.fetch(...), which always sends auth:
  • The protected endpoints are used in authenticated providers:
  • UI callers (exercise/ingredient autocompleters) are inside post-login screens:

Conclusion:

  • With current architecture, requiring auth for those catalog endpoints is compatible with wger-flutter.

@rolandgeider
Copy link
Member

Hi! Would you then block all access to API endpoints that don't send a token in the header?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants