@@ -2,15 +2,13 @@ import cors from "@fastify/cors";
22import formDataPlugin from "@fastify/formbody" ;
33import FastifyPlugin from "fastify-plugin" ;
44import supertokens from "supertokens-node" ;
5- import {
6- errorHandler ,
7- plugin as supertokensPlugin ,
8- } from "supertokens-node/framework/fastify" ;
5+ import { plugin as supertokensPlugin } from "supertokens-node/framework/fastify" ;
96import { verifySession } from "supertokens-node/recipe/session/framework/fastify" ;
107
8+ import { errorHandler } from "./errorHandler" ;
119import init from "./init" ;
1210
13- import type { FastifyError , FastifyInstance } from "fastify" ;
11+ import type { FastifyInstance } from "fastify" ;
1412
1513const plugin = async ( fastify : FastifyInstance ) => {
1614 const { config, log } = fastify ;
@@ -19,16 +17,9 @@ const plugin = async (fastify: FastifyInstance) => {
1917
2018 init ( fastify ) ;
2119
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- ) ;
20+ if ( config . user . supertokens . setErrorHandler !== false ) {
21+ fastify . setErrorHandler ( errorHandler ) ;
22+ }
3223
3324 await fastify . register ( cors , {
3425 origin : config . appOrigin ,
0 commit comments