Hi, I currently use supertokens-node in my backend...
# support-questions-legacy
l
Hi, I currently use supertokens-node in my backend using passwordless authentication. When my client enters the OTP code sent via email, Supertokens checks if the entered code matches. If it's different, it throws an error INCORRECT_USER_INPUT_CODE_ERROR, and if the code is correct, it calls the createNewSession method of ThirdPartyPasswordless. I'd like to allow login for my email with the code 000000 always. I tried to override the method that performs this validation but couldn't succeed. I'd like to know which method performs this validation, if it's possible to override it, and how it would look in my code. thanks!
r
hey @Lucas Dias this can be achieved by overriding the createCode function on the backend.
Copy code
ThirdPartyPasswordless.init({
    contactMethod: "...",
    flowType: "...",
    override: {
        functions: (oI) => {
            return {
                ...oI,
                createCode: async (input) => {
                    if ("email" in input && input.email === "YOUR EMAIL") {
                        return oI.createCode({
                            ...input,
                            userInputCode: "0000000"
                        })
                    }
                    return oI.createCode(input);
                }
            }
        }
    }
})
This goes in the backend config
l
@rp_st Thank you! I understand that instead of overriding the code reading function, I should override the one that sends the code so that when it's my email, I can send the code I define there. Below is an example of how my code looks:
Copy code
ts
recipeList: [
  ThirdPartyPasswordless.init({
    validatePhoneNumber: () => undefined,
    emailDelivery: {
      override: originalImplementation => {
        return {
          ...originalImplementation,
          //...
        }
      },
    },
  }),
  Session.init({
    jwt: {
      enable: true,
    },
    override: {
      functions: function (originalImplementation) {
        return {
          ...originalImplementation,
          createNewSession: async function (input) {
            //...
          },
        }
      },
    },
  }),
]
I'm using "supertokens-node": "^12.1.1" version. I tried as you instructed, but I'm getting the following error: "Property 'createCode' does not exist on type 'RecipeInterface'." Could it be that in this version, the method has a different name?
r
I think you are passing the createCode in the override of emailDelivery. Please double check the code
l
@rp_st i try in this place:
Copy code
ts
Session.init({
    jwt: {
      enable: true,
    },
    override: {
      functions: function (originalImplementation) {
        return {
          ...originalImplementation,
          createCode: async (input) => {
            if ("email" in input && input.email === "YOUR EMAIL") {
                return originalImplementation.createCode({
                    ...input,
                    userInputCode: "0000000"
                })
            }
            return originalImplementation.createCode(input);
          },  
          createNewSession: async function (input) {
            //...
          },
        }
      },
    },
  })
r
It goes in thirdpartypasdwordless not session
Anyway, the code I gave should work for your version.
l
@rp_st I tried to do the example following the syntax of my "emailDelivery" which I had already overwritten, but I think it should be another name there on line 44
r
It goes in override
Of thirdpartypasdwordless
Anyway, the code I gave you is all I can help right now.
l
@rp_st No problem, I would just like to know if the name of the method is createCode, and if there is any documentation about it, I couldn't find it on the website.
r
It is. The code I sent works.
l
thanks!
d
hey @Lucas Dias 👋 This time next week, this channel will become read-only. Please ask any future question in ⁠#1224328457589227540, so that everyone gets better experience. Thanks 🙂
l
@Darko ok, thanks!
7 Views