Registry / auth-security / supertokens-js-override

supertokens-js-override

JSON →
library0.0.4jsnpmunverified

The `supertokens-js-override` package provides foundational helper functions for implementing overrideable interfaces within the SuperTokens ecosystem. Its primary purpose is to enable developers to deeply customize the behavior of SuperTokens SDKs, allowing for the injection of custom logic into authentication and session management processes. This includes modifying how specific functions operate or altering the behavior of exposed APIs. While the package itself is at version `0.0.4`, it serves as a stable, internal dependency for other SuperTokens SDKs (like `supertokens-node` and `supertokens-auth-react`), which are more actively developed. Its release cadence is consequently very slow, as its core utility is mature. Key differentiators include its tight integration with SuperTokens' architecture, enabling method overriding akin to object-oriented `super` calls, and its support for complex customization scenarios directly within the application's backend or frontend code, rather than through external configuration dashboards.

npm install supertokens-js-override
INSTALL
IMPORT
SIG · SUPERTOKENS-JS-OVE
S
supertokens-js-override
auth-securityjavascriptv0.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

buildOverride
import { buildOverride } from 'supertokens-js-override';
const buildOverride = require('supertokens-js-override').buildOverride;
Primarily used by SuperTokens SDKs internally; direct consumer usage is for advanced scenarios or custom plugin development.
TypeOverride
import type { TypeOverride } from 'supertokens-js-override';
Type definition for creating custom override functions. Use for strict type checking in TypeScript projects.

This quickstart demonstrates how to use `buildOverride` to create a new object that modifies specific methods of an `originalService` while retaining others.

import { buildOverride } from 'supertokens-js-override'; // Imagine an 'original' service with a method we want to change const originalService = { getData: (id: string) => `Fetching data for ${id} from original source.`, processInput: (input: string) => `Processing: ${input.toUpperCase()}.`, authCheck: () => true }; // Define an override that modifies 'getData' and adds a custom log to 'processInput' const overriddenService = buildOverride(originalService, (originalImplementation) => { return { ...originalImplementation, getData: (id: string) => { console.log(`[Override] Intercepting data fetch for ID: ${id}`); if (id === 'special-id') { return 'Custom data for special-id!'; } // Call the original implementation for other IDs return originalImplementation.getData(id); }, processInput: (input: string) => { console.log(`[Override] Input received: ${input}`); return originalImplementation.processInput(input); } }; }); console.log(overriddenService.getData('user-123')); // Expected: [Override] Intercepting data fetch for ID: user-123\nFetching data for user-123 from original source. console.log(overriddenService.getData('special-id')); // Expected: [Override] Intercepting data fetch for ID: special-id\nCustom data for special-id! console.log(overriddenService.processInput('hello world')); // Expected: [Override] Input received: hello world\nProcessing: HELLO WORLD. console.log(overriddenService.authCheck()); // Expected: true (original method is preserved)
Debug
Known issues
gotchaThis package is a low-level utility typically used internally by other SuperTokens SDKs (e.g., `supertokens-node`, `supertokens-auth-react`). While `buildOverride` is exported for advanced use cases, developers should primarily use the `override` configuration objects exposed by the higher-level SuperTokens SDKs' `init` functions.
fix
Consult the specific SuperTokens SDK documentation (e.g., `supertokens-node` or `supertokens-auth-react`) for the recommended way to use the `override` feature, which often involves passing an object directly to the recipe's `init` method.
affects: >=0.0.1
breakingGiven the `0.0.x` versioning, even minor version increments could introduce breaking changes to the `buildOverride` function signature or its underlying behavior, although the package has been stable for a long period. Major shifts in SuperTokens architecture might necessitate changes.
fix
Always pin to a specific `0.0.x` version (e.g., `"supertokens-js-override": "0.0.4"`) and review release notes thoroughly before upgrading, especially if directly using `buildOverride`. For indirect usage via other SuperTokens SDKs, follow their upgrade guides.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: originalImplementation.someMethod is not a function
The override function attempted to call a method on `originalImplementation` that does not exist or was not correctly passed to `buildOverride`.
fix
Ensure the `originalImplementation` object provided to `buildOverride` indeed contains the method being called in the override. Verify the type `T` matches the expected interface for the original implementation. Ensure `originalImplementation` is not `undefined` or `null`.
My override logic is not being applied / The original method is still executing without changes.
The override function returned an object that did not correctly replace or wrap the desired method, or the `buildOverride` result was not properly integrated into the system (e.g., in a SuperTokens recipe's `init` function).
fix
Double-check that the `override` function returns an object that either entirely replaces the method or correctly calls `originalImplementation.methodName` as part of its new logic. Ensure the result of `buildOverride` is then used where the modified interface is expected.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
16
OpenAI (training)
1
Resources