@objectstack/plugin-auth 6.5.0 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -460,10 +460,56 @@ function buildDeviceAuthorizationPluginSchema() {
460
460
  }
461
461
 
462
462
  // src/auth-manager.ts
463
+ function isWebContainerRuntime() {
464
+ if (typeof globalThis === "undefined") return false;
465
+ const proc = globalThis.process;
466
+ return Boolean(proc?.versions?.webcontainer) || Boolean(proc?.env?.SHELL?.includes?.("jsh")) || Boolean(proc?.env?.STACKBLITZ);
467
+ }
468
+ var WebContainerRequestStateAsyncLocalStorage = class {
469
+ constructor() {
470
+ this.current = void 0;
471
+ }
472
+ run(store, fn) {
473
+ const prev = this.current;
474
+ this.current = store;
475
+ try {
476
+ const result = fn();
477
+ if (result && typeof result.then === "function") {
478
+ return result.finally(() => {
479
+ this.current = prev;
480
+ });
481
+ }
482
+ this.current = prev;
483
+ return result;
484
+ } catch (err) {
485
+ this.current = prev;
486
+ throw err;
487
+ }
488
+ }
489
+ getStore() {
490
+ return this.current;
491
+ }
492
+ };
493
+ function installWebContainerRequestStatePolyfill() {
494
+ if (!isWebContainerRuntime()) return;
495
+ const sym = /* @__PURE__ */ Symbol.for("better-auth:global");
496
+ const g = globalThis;
497
+ if (!g[sym]) {
498
+ g[sym] = { version: "0.0.0-polyfill", epoch: 0, context: {} };
499
+ }
500
+ if (!g[sym].context) g[sym].context = {};
501
+ if (!g[sym].context.requestStateAsyncStorage) {
502
+ g[sym].context.requestStateAsyncStorage = new WebContainerRequestStateAsyncLocalStorage();
503
+ console.warn(
504
+ "[AuthManager] WebContainer detected: installed synchronous request-state polyfill (node:async_hooks AsyncLocalStorage does not propagate context across await in WebContainer)."
505
+ );
506
+ }
507
+ }
463
508
  var AuthManager = class {
464
509
  constructor(config) {
465
510
  this.auth = null;
466
511
  this.config = config;
512
+ installWebContainerRequestStatePolyfill();
467
513
  if (config.authInstance) {
468
514
  this.auth = config.authInstance;
469
515
  }
@@ -680,8 +726,7 @@ var AuthManager = class {
680
726
  * the native (fast) hasher and never load `@noble/hashes`.
681
727
  */
682
728
  async resolvePasswordHasher() {
683
- const isWebContainer = typeof globalThis !== "undefined" && (Boolean(globalThis.process?.versions?.webcontainer) || Boolean(globalThis.process?.env?.SHELL?.includes?.("jsh")) || Boolean(globalThis.process?.env?.STACKBLITZ));
684
- if (!isWebContainer) return void 0;
729
+ if (!isWebContainerRuntime()) return void 0;
685
730
  try {
686
731
  const { scryptAsync } = await import("@noble/hashes/scrypt.js");
687
732
  const PARAMS = { N: 16384, r: 16, p: 1, dkLen: 64, maxmem: 128 * 16384 * 16 * 2 };