Skip to main content

If you are using our backend SDK that is lesser than the following versions, please visit the older documentation link here.

How to send a custom response

important

This feature is only applicable for users who build their own frontend since our frontend requires on a specific output from the APIs as defined here.

Let's take an example of sending a custom response for the /auth/emailpassword/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 EmailPassword from "supertokens-node/recipe/emailpassword";

EmailPassword.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 versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI