I am encountering the following error: `Error: Thi...
# support-questions-legacy
n
I am encountering the following error:
Error: This function should only be called through the recipe object
Copy code
err: Error: This function should only be called through the recipe object
      at Object._call (/Users/laurinquast/Projects/graphql-hive-2/node_modules/supertokens-js-override/lib/build/getProxyObject.js:17:19)
      at Object.ret.<computed> [as authorisationUrlGET] (/Users/laurinquast/Projects/graphql-hive-2/node_modules/supertokens-js-override/lib/build/getProxyObject.js:27:29)
      at Object.authorisationUrlGET (webpack-internal:///(api)/./src/lib/supertokens/third-party-email-password-node-oidc-provider.ts:103:45)
While trying to compose multiple overrides using a helper function (so code can be isolated).
This is the helper function I wrote:
Copy code
const composeSuperTokensOverrides = (overrides: Array<ThirdPartEmailPasswordTypeInput['override'] | null>) => ({
  apis: (
    originalImplementation: ReturnType<
      Exclude<Exclude<ThirdPartEmailPasswordTypeInput['override'], undefined>['apis'], undefined>
    >,
    builder: OverrideableBuilder<ThirdPartyEmailPasswordNode.APIInterface> | undefined
  ) => {
    let impl = originalImplementation;
    for (const override of overrides) {
      if (typeof override?.apis === 'function') {
        impl = override.apis(impl, builder);
      }
    }
    return impl;
  },
  functions: (
    originalImplementation: ReturnType<
      Exclude<Exclude<ThirdPartEmailPasswordTypeInput['override'], undefined>['functions'], undefined>
    >
  ) => {
    let impl = originalImplementation;
    for (const override of overrides) {
      if (typeof override?.functions === 'function') {
        impl = override.functions(impl);
      }
    }
    return impl;
  },
});
And this is the actual usage:
Copy code
override: composeSuperTokensOverrides([
  getEnsureUserOverrides(internalApi),
  env.auth.organizationOIDC ? getOIDCThirdPartyEmailPasswordNodeOverrides({ internalApi }) : null,
  /**
   * These overrides are only relevant for the legacy Auth0 -> SuperTokens migration (period).
   */
  env.auth.legacyAuth0 ? getAuth0Overrides(env.auth.legacyAuth0) : null,
]),
Any quick ideas?
okay sovled via a bind call 😄
r
We actually have an override builder that’s part of the override function signature that you should use
@porcellus can help with this
p
hi
I think the issue may have been in the overrides you are composing in there, but I'm not sure
anyway, I think you should be able to compose overrides much more easily through the builder the override function gets
it has an override function that kind of emulates inheritance, otherwise you can run into binding issues exactly like the one you got
n
do you have an example of this?
p
we don't, but: you can call
builder.override(overrideFunc)
where overrideFunc in your case is
override.functions
or
override.apis
2 Views