mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-26 17:06:41 -05:00
chore(core): fix error.cause in BetterAuthError (#7347)
This commit is contained in:
@@ -43,16 +43,14 @@ export const jwt = <O extends JwtOptions>(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 = <O extends JwtOptions>(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 '..'",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user