Skip to content

Commit 56d91ed

Browse files
committed
refactor: add setErrorHandler config to toggle setting error supertokens error handler
1 parent 373eb8e commit 56d91ed

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

packages/user/src/supertokens/plugin.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { verifySession } from "supertokens-node/recipe/session/framework/fastify
1010

1111
import init from "./init";
1212

13-
import type { FastifyError, FastifyInstance } from "fastify";
13+
import type {
14+
FastifyError,
15+
FastifyInstance,
16+
FastifyReply,
17+
FastifyRequest,
18+
} from "fastify";
1419

1520
const plugin = async (fastify: FastifyInstance) => {
1621
const { config, log } = fastify;
@@ -19,16 +24,16 @@ const plugin = async (fastify: FastifyInstance) => {
1924

2025
init(fastify);
2126

22-
// Explicitly cast the errorHandler to the correct type
23-
// [RL 2025-04-01] This should be fixed when supertokens-node is updated
24-
fastify.setErrorHandler(
25-
errorHandler() as unknown as (
26-
this: FastifyInstance,
27-
error: FastifyError,
28-
request: import("fastify").FastifyRequest,
29-
reply: import("fastify").FastifyReply,
30-
) => void,
31-
);
27+
if (config.user.supertokens.setErrorHandler !== false) {
28+
fastify.setErrorHandler(
29+
errorHandler() as unknown as (
30+
this: FastifyInstance,
31+
error: FastifyError,
32+
request: FastifyRequest,
33+
reply: FastifyReply,
34+
) => void,
35+
);
36+
}
3237

3338
await fastify.register(cors, {
3439
origin: config.appOrigin,

packages/user/src/supertokens/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface SupertokensConfig {
4747
resetPasswordPath?: string;
4848
emailVerificationPath?: string;
4949
sendUserAlreadyExistsWarning?: boolean;
50+
setErrorHandler?: boolean;
5051
}
5152

5253
export type { SupertokensConfig, SupertokensRecipes };

0 commit comments

Comments
 (0)