Skip to main content
Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react

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 ThirdPartyEmailPassword from "supertokens-auth-react/recipe/thirdpartyemailpassword";

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

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

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

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

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

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

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

} else if (action === "THIRD_PARTY_SIGN_IN_UP") {
// Note: this could either be sign in or sign up.
// we don't know that at the time of the API call
// since all we have is the authorisation code from
// the social provider
}

// events such as sign out are in the
// session recipe pre API hook (See the info box below)

return {
requestInit, url
};

}
})
info

Also checkout the session recipe pre API hook for events such as sign out. These will need to go in the Session.init config object.

Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react