diff --git a/packages/better-auth/src/plugins/jwt/index.ts b/packages/better-auth/src/plugins/jwt/index.ts index ecc3a9c40b..ef8c10fb12 100644 --- a/packages/better-auth/src/plugins/jwt/index.ts +++ b/packages/better-auth/src/plugins/jwt/index.ts @@ -43,16 +43,14 @@ export const jwt = (options?: O) => { // Remote url must be set when using signing function if (options?.jwt?.sign && !options.jwks?.remoteUrl) { throw new BetterAuthError( - "jwks_config", - "jwks.remoteUrl must be set when using jwt.sign", + "options.jwks.remoteUrl must be set when using options.jwt.sign", ); } // Alg is required to be specified when using remote url (needed in openid metadata) if (options?.jwks?.remoteUrl && !options.jwks?.keyPairConfig?.alg) { throw new BetterAuthError( - "jwks_config", - "must specify alg when using the oidc plugin and jwks.remoteUrl", + "options.jwks.keyPairConfig.alg must be specified when using the oidc plugin with options.jwks.remoteUrl", ); } @@ -64,8 +62,7 @@ export const jwt = (options?: O) => { jwksPath.includes("..") ) { throw new BetterAuthError( - "jwks_config", - "jwksPath must be a non-empty string starting with '/' and not contain '..'", + "options.jwks.jwksPath must be a non-empty string starting with '/' and not contain '..'", ); } diff --git a/packages/better-auth/src/plugins/jwt/jwt.test.ts b/packages/better-auth/src/plugins/jwt/jwt.test.ts index bf3db10eb5..8ef8be9389 100644 --- a/packages/better-auth/src/plugins/jwt/jwt.test.ts +++ b/packages/better-auth/src/plugins/jwt/jwt.test.ts @@ -419,7 +419,9 @@ describe("jwt - remote signing", async () => { }), ], }), - ).toThrowError("jwks_config"); + ).toThrowError( + "options.jwks.remoteUrl must be set when using options.jwt.sign", + ); }); }); @@ -435,7 +437,9 @@ describe("jwt - remote url", async () => { }), ], }), - ).toThrowError("jwks_config"); + ).toThrowError( + "options.jwks.keyPairConfig.alg must be specified when using the oidc plugin with options.jwks.remoteUrl", + ); }); it("should accept remoteUrl with alg specified", async () => { diff --git a/packages/better-auth/src/utils/url.ts b/packages/better-auth/src/utils/url.ts index 3546be7f33..4caa2ba71f 100644 --- a/packages/better-auth/src/utils/url.ts +++ b/packages/better-auth/src/utils/url.ts @@ -27,7 +27,9 @@ function assertHasProtocol(url: string): void { } throw new BetterAuthError( `Invalid base URL: ${url}. Please provide a valid base URL.`, - String(error), + { + cause: error, + }, ); } } diff --git a/packages/core/src/error/index.ts b/packages/core/src/error/index.ts index 7182a39f12..329b8640d3 100644 --- a/packages/core/src/error/index.ts +++ b/packages/core/src/error/index.ts @@ -1,11 +1,10 @@ import { APIError as BaseAPIError } from "better-call/error"; export class BetterAuthError extends Error { - constructor(message: string, cause?: string | undefined) { - super(message); + constructor(message: string, options?: { cause?: unknown | undefined }) { + super(message, options); this.name = "BetterAuthError"; this.message = message; - this.cause = cause; this.stack = ""; } }