Skip to main content
Version: 8.2.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 startsSuperTokens.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        }    }}
Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react