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

Skip to main content
Version: 8.1.X

Sending Requests with Fetch

The init function call automatically adds interceptors to fetch. So there is nothing else that needs to be done.

import SuperTokens from 'supertokens-website';

// call this when your app starts
SuperTokens.init({
apiDomain: "https://api.example.com"
});

async function doAPICalls() {
try {
// make API call as usual
let fetchConfig = { ... };
let response = await fetch("/someAPI", fetchConfig);

// handle response
if (response.status !== 200) {
throw response;
}
let data = await response.json();
let someField = data.someField;
// ...
} catch (err) {
if (err.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