Skip to content

Commit 8e85755

Browse files
committed
add fallback for route handlers
1 parent 1010447 commit 8e85755

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

lib/build/genericComponentOverrideContext.js

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/types.d.ts

Lines changed: 15 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/superTokens.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,18 @@ export default class SuperTokens {
140140

141141
const pluginRouteHandlers = plugins[pluginIndex].routeHandlers;
142142
if (pluginRouteHandlers) {
143-
const result = pluginRouteHandlers(config, this.pluginList, package_version);
144-
if (result.status === "ERROR") {
145-
throw new Error(result.message);
143+
let handlers: PluginRouteHandler[] = [];
144+
if (typeof pluginRouteHandlers === "function") {
145+
const result = pluginRouteHandlers(config, this.pluginList, package_version);
146+
if (result.status === "ERROR") {
147+
throw new Error(result.message);
148+
}
149+
handlers = result.routeHandlers;
150+
} else {
151+
handlers = pluginRouteHandlers;
146152
}
147-
this.pluginRouteHandlers.push(...result.routeHandlers);
153+
154+
this.pluginRouteHandlers.push(...handlers);
148155
}
149156
}
150157

lib/ts/types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,13 @@ export type SuperTokensPlugin = {
543543
};
544544
};
545545
generalAuthRecipeComponentOverrides?: AuthRecipeComponentOverrideMap;
546-
routeHandlers?: (
547-
config: Omit<SuperTokensConfig, "experimental" | "recipeList">,
548-
allPlugins: Pick<SuperTokensPlugin, "id" | "version" | "exports">[],
549-
sdkVersion: string
550-
) => { status: "OK"; routeHandlers: PluginRouteHandler[] } | { status: "ERROR"; message: string };
546+
routeHandlers?:
547+
| ((
548+
config: Omit<SuperTokensConfig, "experimental" | "recipeList">,
549+
allPlugins: Pick<SuperTokensPlugin, "id" | "version" | "exports">[],
550+
sdkVersion: string
551+
) => { status: "OK"; routeHandlers: PluginRouteHandler[] } | { status: "ERROR"; message: string })
552+
| PluginRouteHandler[];
551553
config?: (
552554
config: Omit<SuperTokensConfig, "experimental" | "recipeList">
553555
) => Omit<SuperTokensConfig, "experimental" | "recipeList"> | undefined;

0 commit comments

Comments
 (0)