Skip to content

Conversation

brionmario
Copy link
Member

@brionmario brionmario commented Sep 8, 2025

Purpose

This pull request introduces significant improvements to the browser package, focusing on enhanced web worker integration, error handling, and configuration flexibility. The main changes include switching to an inline web worker build approach, improving error serialization and propagation between threads, and adding support for configurable storage mechanisms. These updates help modernize the codebase, improve reliability, and make the authentication client more adaptable for different environments.

Web Worker Integration & Build System:

  • Switched to using the esbuild-plugin-inline-worker for bundling web workers, updating the build configuration in esbuild.config.mjs and adding the dependency to package.json. This allows the worker code to be bundled inline and ensures proper polyfills for browser environments. [1] [2] [3]
  • Renamed worker.ts to web.worker.ts and added polyfills for Buffer and global to ensure compatibility in browser worker contexts.
  • Updated references and logic in the legacy client to use the new web.worker.ts and enabled dynamic worker instantiation. [1] [2] [3] [4]

Error Handling Improvements:

  • Enhanced error serialization in MessageUtils to robustly handle Error objects, non-Error objects, and primitives, ensuring errors are reliably transferred between main thread and worker.
  • Improved error propagation in web-worker-client.ts by parsing errors safely and wrapping unknown or malformed errors in a custom AsgardeoAuthException. [1] [2] [3]

Configuration Flexibility:

  • Extended the AsgardeoBrowserConfig type to support multiple storage options, including sessionStorage, localStorage, browserMemory, and webWorker. [1] [2]
  • Updated the React context to require core authentication methods and expose the selected storage mechanism, improving type safety and developer experience. [1] [2] [3]

Related Issues

Related PRs

  • N/A

Checklist

  • e2e cypress tests locally verified.
  • Manual test round performed and verified.
  • UX/UI review done on the final implementation.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided. (Add links if there are any)
  • Integration tests provided. (Add links if there are any)

Security checks

@brionmario brionmario changed the title fix: fix web-worker related issues fix: fix web-worker related issues Sep 8, 2025
@brionmario brionmario merged commit d76e8ff into asgardeo:main Sep 8, 2025
2 of 4 checks passed
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