Skip to main content
Which UI do you use?
Custom UI
Pre built UI

Pre API Hook

This function is called before any API call is being made to your backend from our frontend SDK. You can use this to change the request body / url / header or any other request property.

import EmailPassword from "supertokens-auth-react/recipe/emailpassword";

EmailPassword.init({
preAPIHook: async (context) => {
let url = context.url;

// is the fetch config object that contains the header, body etc..
let requestInit = context.requestInit;

let action = context.action;
if (action === "EMAIL_EXISTS") {

} else if (action === "SEND_RESET_PASSWORD_EMAIL") {

} else if (action === "EMAIL_PASSWORD_SIGN_IN") {

} else if (action === "EMAIL_PASSWORD_SIGN_UP") {

} else if (action === "SUBMIT_NEW_PASSWORD") {

} else if (action === "VERIFY_EMAIL") {

}

// events such as sign out are in the
// session recipe pre API hook (See the info box below)
return {
requestInit, url
};
}
})

Reading custom request information in the backend#

Visit this page to learn how to read custom headers etc from the request on the backend.

Looking for older version of the documentation?
Which UI do you use?
Custom UI
Pre built UI