@objectstack/plugin-auth 6.4.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.js +47 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -524,10 +524,56 @@ function buildDeviceAuthorizationPluginSchema() {
|
|
|
524
524
|
}
|
|
525
525
|
|
|
526
526
|
// src/auth-manager.ts
|
|
527
|
+
function isWebContainerRuntime() {
|
|
528
|
+
if (typeof globalThis === "undefined") return false;
|
|
529
|
+
const proc = globalThis.process;
|
|
530
|
+
return Boolean(proc?.versions?.webcontainer) || Boolean(proc?.env?.SHELL?.includes?.("jsh")) || Boolean(proc?.env?.STACKBLITZ);
|
|
531
|
+
}
|
|
532
|
+
var WebContainerRequestStateAsyncLocalStorage = class {
|
|
533
|
+
constructor() {
|
|
534
|
+
this.current = void 0;
|
|
535
|
+
}
|
|
536
|
+
run(store, fn) {
|
|
537
|
+
const prev = this.current;
|
|
538
|
+
this.current = store;
|
|
539
|
+
try {
|
|
540
|
+
const result = fn();
|
|
541
|
+
if (result && typeof result.then === "function") {
|
|
542
|
+
return result.finally(() => {
|
|
543
|
+
this.current = prev;
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
this.current = prev;
|
|
547
|
+
return result;
|
|
548
|
+
} catch (err) {
|
|
549
|
+
this.current = prev;
|
|
550
|
+
throw err;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
getStore() {
|
|
554
|
+
return this.current;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
function installWebContainerRequestStatePolyfill() {
|
|
558
|
+
if (!isWebContainerRuntime()) return;
|
|
559
|
+
const sym = /* @__PURE__ */ Symbol.for("better-auth:global");
|
|
560
|
+
const g = globalThis;
|
|
561
|
+
if (!g[sym]) {
|
|
562
|
+
g[sym] = { version: "0.0.0-polyfill", epoch: 0, context: {} };
|
|
563
|
+
}
|
|
564
|
+
if (!g[sym].context) g[sym].context = {};
|
|
565
|
+
if (!g[sym].context.requestStateAsyncStorage) {
|
|
566
|
+
g[sym].context.requestStateAsyncStorage = new WebContainerRequestStateAsyncLocalStorage();
|
|
567
|
+
console.warn(
|
|
568
|
+
"[AuthManager] WebContainer detected: installed synchronous request-state polyfill (node:async_hooks AsyncLocalStorage does not propagate context across await in WebContainer)."
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
527
572
|
var AuthManager = class {
|
|
528
573
|
constructor(config) {
|
|
529
574
|
this.auth = null;
|
|
530
575
|
this.config = config;
|
|
576
|
+
installWebContainerRequestStatePolyfill();
|
|
531
577
|
if (config.authInstance) {
|
|
532
578
|
this.auth = config.authInstance;
|
|
533
579
|
}
|
|
@@ -744,8 +790,7 @@ var AuthManager = class {
|
|
|
744
790
|
* the native (fast) hasher and never load `@noble/hashes`.
|
|
745
791
|
*/
|
|
746
792
|
async resolvePasswordHasher() {
|
|
747
|
-
|
|
748
|
-
if (!isWebContainer) return void 0;
|
|
793
|
+
if (!isWebContainerRuntime()) return void 0;
|
|
749
794
|
try {
|
|
750
795
|
const { scryptAsync } = await import("@noble/hashes/scrypt.js");
|
|
751
796
|
const PARAMS = { N: 16384, r: 16, p: 1, dkLen: 64, maxmem: 128 * 16384 * 16 * 2 };
|