<commit_before>let accessToken = null;
let username = null;
let password = <PASSWORD>;
let axios = null;


async function login() {
    // Exchange password for access token
    axios.emitter.emit('loggingIn');

    try {
        const res = await axios
            .post('accesstokens', {
                shopwareId: username,
                password,
            }, {
                noToken: true,
            });

        axios.emitter.emit('loginSuccessful');
        // Save access token
        accessToken = res.data.token;

        return true;
    } catch (err) {
        if (err.response && err.response.unauthorized) {
            throw new Error(`Login failed: ${err.message}`);
        }

        throw err;
    }
}

async function getAccessToken() {
    if (accessToken) {
        return accessToken;
    }

    // Login to get an access token
    await login();

    return accessToken;
}

module.exports = (customAxios, user, pass) => {
    username = user;
    password = <PASSWORD>;
    axios = customAxios;
    customAxios.interceptors.request.use(async (config) => {
        if (!config.noToken) {
            const token = await getAccessToken();
            if (config.headers) {
                config.headers['X-Shopware-Token'] = token;
            } else {
                config.headers = { 'X-Shopware-Token': token };
            }

            return config;
        }

        return config;
    },
        error => Promise.reject(error)
    );

    return customAxios;
};<commit_msg>Add re-login once on 401 response<commit_after>let accessToken = null;
let username = null;
let password = <PASSWORD>;
let axios = null;


async function login() {
    // Exchange password for access token
    axios.emitter.emit('loggingIn');

    try {
        const res = await axios
            .post('accesstokens', {
                shopwareId: username,
                password,
            }, {
                noToken: true,
            });

        axios.emitter.emit('loginSuccessful');
        // Save access token
        accessToken = res.data.token;

        return true;
    } catch (err) {
        if (err.response && err.response.unauthorized) {
            throw new Error(`Login failed: ${err.message}`);
        }

        throw err;
    }
}

async function getAccessToken() {
    if (accessToken) {
        return accessToken;
    }

    // Login to get an access token
    await login();

    return accessToken;
}

module.exports = (customAxios, user, pass) => {
    username = user;
    password = <PASSWORD>;
    axios = customAxios;
    customAxios.interceptors.request.use(async (config) => {
        if (!config.noToken) {
            const token = await getAccessToken();
            if (config.headers) {
                config.headers['X-Shopware-Token'] = token;
            } else {
                config.headers = { 'X-Shopware-Token': token };
            }

            return config;
        }

        return config;
    },
        error => Promise.reject(error)
    );

    customAxios.interceptors.response.use(async response => response,
        (error) => {
            // retry request once on 401
            if (error.response.status === 401 && error.config && !error.config.isRetryRequest) {
                error.config.isRetryRequest = true;
                accessToken = null;
                axios.emitter.emit('info', 'Renewing auth data...');

                return customAxios(error.config);
            }

            return Promise.reject(error);
        });

    return customAxios;
};
{'fraction_non_alphanumeric': 0.11569783768604325, 'fraction_numerical': 0.002527379949452401, 'mean_word_length': 1.7253251721499618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3720431', 'n_tokens_mistral': 1024, 'n_tokens_neox': 974, 'n_words': 237}