Skip to main content

How to send a custom response by overriding the API Interface

Let's take an example of sending a custom response for the /auth/signup/email/exists GET API (does email exist).

We need to first override the function for that API (emailExistsGET) and then use the response object in the input param to send a custom response.

The function signature expects an return type that has a certain shape, therefore, we must still return a valid response object from the function, but that will be ignored since you have already sent a response to the client.

import Passwordless from "supertokens-node/recipe/passwordless";

Passwordless.init({

override: {
apis: (originalImplementation) => {
return {
...originalImplementation,
emailExistsGET: async function (input) {

// we can send a custom response like this:
input.options.res.setStatusCode(200); // or any other status code
input.options.res.sendJSONResponse({
message: "my custom response",
//...
})

// this return doesn't matter. But we must do it
// cause the function signature expects a response.
return {
status: "OK",
exists: false
};
}
}
}
}
})
Looking for older version of the documentation?
Which UI do you use?
Custom UI
Pre built UI