This SDK documentation is outdated. Please do not refer to it, and instead visit the User Guides section.

Skip to main content
Version: 8.2.X

Sending Requests with Axios

Step 1) Add axios interceptors#

import SuperTokens from 'supertokens-website';

SuperTokens.addAxiosInterceptors(axios);
important

To be called on each axios instances that is being imported.

Step 2) Use axios as usual#

import SuperTokens from 'supertokens-website';
import axios from "axios";
SuperTokens.addAxiosInterceptors(axios);

SuperTokens.init({
apiDomain: "https://api.example.com"
});

async function doAPICalls() {
try {
let postData = { ... };
let response = await axios({url: "someAPI", method: "post", data: postData });
let data = await response.data;
let someField = data.someField;
} catch (err) {
if (err.response !== undefined && err.response.status === 401) {
// redirect user to login
} else {
// handle error
}
}
}
Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI