@objectstack/plugin-auth 3.2.6 → 3.2.7
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +8 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +66 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/auth-manager.test.ts +345 -0
- package/src/auth-manager.ts +71 -2
- package/src/auth-plugin.test.ts +89 -0
- package/src/auth-plugin.ts +21 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/plugin-auth@3.2.
|
|
2
|
+
> @objectstack/plugin-auth@3.2.7 build /home/runner/work/spec/spec/packages/plugins/plugin-auth
|
|
3
3
|
> tsup --config ../../../tsup.config.ts
|
|
4
4
|
|
|
5
5
|
▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
|
|
@@ -66,13 +66,13 @@
|
|
|
66
66
|
╵ [32m~~~~~~~~~[0m
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
[
|
|
73
|
-
[
|
|
74
|
-
[
|
|
69
|
+
[32mCJS[39m [1mdist/index.js [22m[32m45.05 KB[39m
|
|
70
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m93.22 KB[39m
|
|
71
|
+
[32mCJS[39m ⚡️ Build success in 95ms
|
|
72
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m41.57 KB[39m
|
|
73
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m92.69 KB[39m
|
|
74
|
+
[32mESM[39m ⚡️ Build success in 95ms
|
|
75
75
|
[34mDTS[39m Build start
|
|
76
|
-
[32mDTS[39m ⚡️ Build success in
|
|
77
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m866.
|
|
78
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m866.
|
|
76
|
+
[32mDTS[39m ⚡️ Build success in 9346ms
|
|
77
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m866.76 KB[39m
|
|
78
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m866.76 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -148,6 +148,17 @@ declare class AuthManager {
|
|
|
148
148
|
* Generate a secure secret if not provided
|
|
149
149
|
*/
|
|
150
150
|
private generateSecret;
|
|
151
|
+
/**
|
|
152
|
+
* Update the base URL at runtime.
|
|
153
|
+
*
|
|
154
|
+
* This **must** be called before the first request triggers lazy
|
|
155
|
+
* initialisation of the better-auth instance — typically from a
|
|
156
|
+
* `kernel:ready` hook where the actual server port is known.
|
|
157
|
+
*
|
|
158
|
+
* If the auth instance has already been created this is a no-op and
|
|
159
|
+
* a warning is emitted.
|
|
160
|
+
*/
|
|
161
|
+
setRuntimeBaseUrl(url: string): void;
|
|
151
162
|
/**
|
|
152
163
|
* Get the underlying better-auth instance
|
|
153
164
|
* Useful for advanced use cases
|
package/dist/index.d.ts
CHANGED
|
@@ -148,6 +148,17 @@ declare class AuthManager {
|
|
|
148
148
|
* Generate a secure secret if not provided
|
|
149
149
|
*/
|
|
150
150
|
private generateSecret;
|
|
151
|
+
/**
|
|
152
|
+
* Update the base URL at runtime.
|
|
153
|
+
*
|
|
154
|
+
* This **must** be called before the first request triggers lazy
|
|
155
|
+
* initialisation of the better-auth instance — typically from a
|
|
156
|
+
* `kernel:ready` hook where the actual server port is known.
|
|
157
|
+
*
|
|
158
|
+
* If the auth instance has already been created this is a no-op and
|
|
159
|
+
* a warning is emitted.
|
|
160
|
+
*/
|
|
161
|
+
setRuntimeBaseUrl(url: string): void;
|
|
151
162
|
/**
|
|
152
163
|
* Get the underlying better-auth instance
|
|
153
164
|
* Useful for advanced use cases
|
package/dist/index.js
CHANGED
|
@@ -399,10 +399,28 @@ var AuthManager = class {
|
|
|
399
399
|
verification: {
|
|
400
400
|
...AUTH_VERIFICATION_CONFIG
|
|
401
401
|
},
|
|
402
|
-
//
|
|
402
|
+
// Social / OAuth providers
|
|
403
|
+
...this.config.socialProviders ? { socialProviders: this.config.socialProviders } : {},
|
|
404
|
+
// Email and password configuration
|
|
403
405
|
emailAndPassword: {
|
|
404
|
-
enabled: true
|
|
406
|
+
enabled: this.config.emailAndPassword?.enabled ?? true,
|
|
407
|
+
...this.config.emailAndPassword?.disableSignUp != null ? { disableSignUp: this.config.emailAndPassword.disableSignUp } : {},
|
|
408
|
+
...this.config.emailAndPassword?.requireEmailVerification != null ? { requireEmailVerification: this.config.emailAndPassword.requireEmailVerification } : {},
|
|
409
|
+
...this.config.emailAndPassword?.minPasswordLength != null ? { minPasswordLength: this.config.emailAndPassword.minPasswordLength } : {},
|
|
410
|
+
...this.config.emailAndPassword?.maxPasswordLength != null ? { maxPasswordLength: this.config.emailAndPassword.maxPasswordLength } : {},
|
|
411
|
+
...this.config.emailAndPassword?.resetPasswordTokenExpiresIn != null ? { resetPasswordTokenExpiresIn: this.config.emailAndPassword.resetPasswordTokenExpiresIn } : {},
|
|
412
|
+
...this.config.emailAndPassword?.autoSignIn != null ? { autoSignIn: this.config.emailAndPassword.autoSignIn } : {},
|
|
413
|
+
...this.config.emailAndPassword?.revokeSessionsOnPasswordReset != null ? { revokeSessionsOnPasswordReset: this.config.emailAndPassword.revokeSessionsOnPasswordReset } : {}
|
|
405
414
|
},
|
|
415
|
+
// Email verification
|
|
416
|
+
...this.config.emailVerification ? {
|
|
417
|
+
emailVerification: {
|
|
418
|
+
...this.config.emailVerification.sendOnSignUp != null ? { sendOnSignUp: this.config.emailVerification.sendOnSignUp } : {},
|
|
419
|
+
...this.config.emailVerification.sendOnSignIn != null ? { sendOnSignIn: this.config.emailVerification.sendOnSignIn } : {},
|
|
420
|
+
...this.config.emailVerification.autoSignInAfterVerification != null ? { autoSignInAfterVerification: this.config.emailVerification.autoSignInAfterVerification } : {},
|
|
421
|
+
...this.config.emailVerification.expiresIn != null ? { expiresIn: this.config.emailVerification.expiresIn } : {}
|
|
422
|
+
}
|
|
423
|
+
} : {},
|
|
406
424
|
// Session configuration
|
|
407
425
|
session: {
|
|
408
426
|
...AUTH_SESSION_CONFIG,
|
|
@@ -412,7 +430,18 @@ var AuthManager = class {
|
|
|
412
430
|
// 1 day default
|
|
413
431
|
},
|
|
414
432
|
// better-auth plugins — registered based on AuthPluginConfig flags
|
|
415
|
-
plugins: this.buildPluginList()
|
|
433
|
+
plugins: this.buildPluginList(),
|
|
434
|
+
// Trusted origins for CSRF protection (supports wildcards like "https://*.example.com")
|
|
435
|
+
...this.config.trustedOrigins?.length ? { trustedOrigins: this.config.trustedOrigins } : {},
|
|
436
|
+
// Advanced options (cross-subdomain cookies, secure cookies, CSRF, etc.)
|
|
437
|
+
...this.config.advanced ? {
|
|
438
|
+
advanced: {
|
|
439
|
+
...this.config.advanced.crossSubDomainCookies ? { crossSubDomainCookies: this.config.advanced.crossSubDomainCookies } : {},
|
|
440
|
+
...this.config.advanced.useSecureCookies != null ? { useSecureCookies: this.config.advanced.useSecureCookies } : {},
|
|
441
|
+
...this.config.advanced.disableCSRFCheck != null ? { disableCSRFCheck: this.config.advanced.disableCSRFCheck } : {},
|
|
442
|
+
...this.config.advanced.cookiePrefix != null ? { cookiePrefix: this.config.advanced.cookiePrefix } : {}
|
|
443
|
+
}
|
|
444
|
+
} : {}
|
|
416
445
|
};
|
|
417
446
|
return (0, import_better_auth.betterAuth)(betterAuthConfig);
|
|
418
447
|
}
|
|
@@ -482,6 +511,25 @@ var AuthManager = class {
|
|
|
482
511
|
}
|
|
483
512
|
return envSecret;
|
|
484
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Update the base URL at runtime.
|
|
516
|
+
*
|
|
517
|
+
* This **must** be called before the first request triggers lazy
|
|
518
|
+
* initialisation of the better-auth instance — typically from a
|
|
519
|
+
* `kernel:ready` hook where the actual server port is known.
|
|
520
|
+
*
|
|
521
|
+
* If the auth instance has already been created this is a no-op and
|
|
522
|
+
* a warning is emitted.
|
|
523
|
+
*/
|
|
524
|
+
setRuntimeBaseUrl(url) {
|
|
525
|
+
if (this.auth) {
|
|
526
|
+
console.warn(
|
|
527
|
+
"[AuthManager] setRuntimeBaseUrl() called after the auth instance was already created \u2014 ignoring. Ensure this method is called before the first request."
|
|
528
|
+
);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
this.config = { ...this.config, baseUrl: url };
|
|
532
|
+
}
|
|
485
533
|
/**
|
|
486
534
|
* Get the underlying better-auth instance
|
|
487
535
|
* Useful for advanced use cases
|
|
@@ -565,6 +613,21 @@ var AuthPlugin = class {
|
|
|
565
613
|
} catch {
|
|
566
614
|
}
|
|
567
615
|
if (httpServer) {
|
|
616
|
+
const serverWithPort = httpServer;
|
|
617
|
+
if (this.authManager && typeof serverWithPort.getPort === "function") {
|
|
618
|
+
const actualPort = serverWithPort.getPort();
|
|
619
|
+
if (actualPort) {
|
|
620
|
+
const configuredUrl = this.options.baseUrl || "http://localhost:3000";
|
|
621
|
+
const configuredOrigin = new URL(configuredUrl).origin;
|
|
622
|
+
const actualUrl = `http://localhost:${actualPort}`;
|
|
623
|
+
if (configuredOrigin !== actualUrl) {
|
|
624
|
+
this.authManager.setRuntimeBaseUrl(actualUrl);
|
|
625
|
+
ctx.logger.info(
|
|
626
|
+
`Auth baseUrl auto-updated to ${actualUrl} (configured: ${configuredUrl})`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
568
631
|
this.registerAuthRoutes(httpServer, ctx);
|
|
569
632
|
ctx.logger.info(`Auth routes registered at ${this.options.basePath}`);
|
|
570
633
|
} else {
|