<commit_before>import { Component } from 'react';

function getJSON(url) {
  return fetch(url, {
    cache: 'no-cache',
    credentials: 'same-origin',
    headers: {
      'content-type': 'application/json',
      Accept: 'application/json',
    },
    mode: 'cors',
    redirect: 'follow',
  }).then(response => response.json());
}

function postJSON(url, data = {}) {
  return fetch(url, {
    body: JSON.stringify(data),
    cache: 'no-cache',
    credentials: 'same-origin',
    headers: {
      'content-type': 'application/json',
      Accept: 'application/json',
    },
    method: 'POST',
    mode: 'cors',
    redirect: 'follow',
  }).then(response => response.json());
}

class Session extends Component {
  state = {
    session: {},
    isLoading: true,
  };

  componentDidMount() {
    this.getSession();
  }

  getSession = () => {
    const { sessionPath } = this.props;
    // Avoid an extra re-render
    if (!this.state.isLoading) {
      this.setState({ isLoading: true });
    }
    getJSON(sessionPath).then(data => {
      this.setState({ session: data, isLoading: false });
    });
  };

  signIn = ({ username, password }) => {
    const { signinPath } = this.props;
    postJSON(signinPath, { username, password })
      .then(() => this.getSession())
      .catch(error => console.error(error));
  };

  signOut = () => {
    const { signoutPath } = this.props;
    this.setState({ isLoading: true });
    postJSON(signoutPath)
      .then(() => this.getSession())<commit_msg>Adding autoSignout functionality to Session provider<commit_after>import { Component } from 'react';

function getJSON(url) {
  return fetch(url, {
    cache: 'no-cache',
    credentials: 'same-origin',
    headers: {
      'content-type': 'application/json',
      Accept: 'application/json',
    },
    mode: 'cors',
    redirect: 'follow',
  }).then(response => response.json());
}

function postJSON(url, data = {}) {
  return fetch(url, {
    body: JSON.stringify(data),
    cache: 'no-cache',
    credentials: 'same-origin',
    headers: {
      'content-type': 'application/json',
      Accept: 'application/json',
    },
    method: 'POST',
    mode: 'cors',
    redirect: 'follow',
  }).then(response => response.json());
}

class Session extends Component {
  state = {
    session: {},
    isLoading: true,
  };

  componentDidMount() {
    const { autoSignout, loadSession } = this.props;
    if (autoSignout) {
      this.signOut();
    } else {
      this.getSession();
    }
  }

  getSession = () => {
    const { sessionPath } = this.props;
    // Avoid an extra re-render
    if (!this.state.isLoading) {
      this.setState({ isLoading: true });
    }
    getJSON(sessionPath).then(data => {
      this.setState({ session: data, isLoading: false });
    });
  };

  signIn = ({ username, password }) => {
    const { signinPath } = this.props;
    postJSON(signinPath, { username, password })
      .then(() => this.getSession())
      .catch(error => console.error(error));
  };

  signOut = () => {
    const { signoutPath } = this.props;
    this.setState({ isLoading: true });
    postJSON(signoutPath)
      .then(() => this.getSession())
{'fraction_non_alphanumeric': 0.17308907138344914, 'fraction_numerical': 0.0, 'mean_word_length': 2.8110709987966307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '7580359', 'n_tokens_mistral': 999, 'n_tokens_neox': 1001, 'n_words': 210}