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.
- ReactJS
- Angular
- Vue
Important
SuperTokens does not provide non-React UI components. So we will be using the
supertokens-auth-react
SDK and will inject the React components to show the UI. Therefore, the code snippet below refers to the supertokens-auth-react
SDK.import ThirdPartyPasswordless from "supertokens-auth-react/recipe/thirdpartypasswordless";
ThirdPartyPasswordless.init({
contactMethod: "EMAIL", // This example will work with any contactMethod.
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 === "PASSWORDLESS_CONSUME_CODE") {
} else if (action === "PASSWORDLESS_CREATE_CODE") {
} else if (action === "PASSWORDLESS_RESEND_CODE") {
} else if (action === "PHONE_NUMBER_EXISTS") {
}
// events such as sign out are in the
// session recipe pre API hook (See the info box below)
return {
requestInit, url
};
}
})
Important
SuperTokens does not provide non-React UI components. So we will be using the
supertokens-auth-react
SDK and will inject the React components to show the UI. Therefore, the code snippet below refers to the supertokens-auth-react
SDK.import ThirdPartyPasswordless from "supertokens-auth-react/recipe/thirdpartypasswordless";
ThirdPartyPasswordless.init({
contactMethod: "EMAIL", // This example will work with any contactMethod.
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 === "PASSWORDLESS_CONSUME_CODE") {
} else if (action === "PASSWORDLESS_CREATE_CODE") {
} else if (action === "PASSWORDLESS_RESEND_CODE") {
} else if (action === "PHONE_NUMBER_EXISTS") {
}
// events such as sign out are in the
// session recipe pre API hook (See the info box below)
return {
requestInit, url
};
}
})
import ThirdPartyPasswordless from "supertokens-auth-react/recipe/thirdpartypasswordless";
ThirdPartyPasswordless.init({
contactMethod: "EMAIL", // This example will work with any contactMethod.
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 === "PASSWORDLESS_CONSUME_CODE") {
} else if (action === "PASSWORDLESS_CREATE_CODE") {
} else if (action === "PASSWORDLESS_RESEND_CODE") {
} else if (action === "PHONE_NUMBER_EXISTS") {
}
// 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.
#
Reading custom request information in the backendVisit this page to learn how to read custom headers etc from the request on the backend.