Skip to content

Fix login redirect issues with subpath handling in WUD - #1138

Open
balaji-g42 wants to merge 2 commits into
getwud:mainfrom
balaji-g42:contribution/fix-subpath-basepath-auth-redirect
Open

Fix login redirect issues with subpath handling in WUD#1138
balaji-g42 wants to merge 2 commits into
getwud:mainfrom
balaji-g42:contribution/fix-subpath-basepath-auth-redirect

Conversation

@balaji-g42

Copy link
Copy Markdown
Contributor

This pull request introduces improvements to how public URLs and paths are constructed and handled across both the backend and frontend, ensuring correct behavior when a base path is configured. It adds comprehensive tests for these scenarios and updates service worker registration and PWA configuration to better handle dynamic base paths.

Backend URL Construction and Testing:

  • Enhanced the getPublicUrl function in app/configuration/index.ts to correctly append the server base path to the public URL or request origin, and updated its logic to handle cases where both WUD_PUBLIC_URL and WUD_SERVER_BASEPATH are set.
  • Added new tests in app/configuration/index.test.ts to verify getPublicUrl behavior with different combinations of environment variables and request origins.

Frontend URL Construction and Testing:

  • Updated the url function in ui/src/services/base.ts to ensure paths are joined correctly, always inserting a slash between the base path and the requested path, and preventing double slashes.
  • Added tests in ui/tests/services/base.spec.ts to verify the correct joining of base paths and paths in different scenarios, including with and without trailing slashes.

Service Worker and PWA Configuration:

  • Modified service worker registration in ui/src/registerServiceWorker.ts to use the updated url function for determining the service worker script path, ensuring compatibility with dynamic base paths.
  • Updated ui/vue.config.js to exclude index.html from the service worker precache, as it is generated dynamically per request with base path injection.

Fixes several related bugs that surface when running WUD behind a
reverse proxy with a stripped subpath (WUD_SERVER_BASEPATH), causing
session-expiry redirects to land on /login instead of /<basepath>/login:

- getPublicUrl() never appended the configured basepath, so OIDC
  redirect_uri and post-login redirects dropped the subpath entirely.
- url() concatenated basepath and path without ensuring a separating
  slash, breaking API calls whenever basepath had no trailing slash
  (e.g. "/wud" + "auth/strategies" -> "/wudauth/strategies").
- registerServiceWorker.ts registered the service worker against the
  build-time process.env.BASE_URL instead of the runtime-injected
  basepath.
- The service worker precached index.html, so Workbox's default
  directoryIndex mapping served a stale, non-basepath-injected shell
  for navigation requests instead of the live per-request server
  response, permanently freezing the wrong basepath for the SW's
  lifetime. index.html is now excluded from the precache manifest.
Replace console.log/error fallbacks with eventBus notifications or
silent handling to satisfy no-console lint rule in production builds.
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