<commit_before>import React from 'react';
import './style.scss';

class Authorization extends React.Component {
  constructor() {
    super();
    this.state = { showRetry: false, retries: 0 };
  }

  async componentDidMount() {
    await this.props.checkAuthentication();
    await this.props.checkToken();
  }

  render() {
    const { loginRequired, tokenRequired, authenticated, registrationToken, iaaAuth, iaaCheck, iaaRequired, children, path, resetState } = this.props;

    if (authenticated !== null && iaaAuth !== null) {
      // If we navigate and are not authenticated but have a token, go back to register
      if (tokenRequired && !authenticated && !registrationToken) {
        console.log('tokenRequired');
        window.location = `/`;
      }

      if (loginRequired && !authenticated && !registrationToken) {
        // because the state is persisted to localStorage and we tried authenticating already
        // state.authenticated will be reloaded as false intead of null, causing a redirect loop
        resetState();
        window.location = `/login?returnUrl=${path}`;<commit_msg>This fixes the issue when you click back in the browser on /register and it gets stuck in an infinite auth loop<commit_after>import React from 'react';
import './style.scss';

class Authorization extends React.Component {
  constructor() {
    super();
    this.state = { showRetry: false, retries: 0 };
  }

  async componentDidMount() {
    await this.props.checkAuthentication();
    await this.props.checkToken();
  }

  render() {
    const { loginRequired, tokenRequired, authenticated, registrationToken, iaaAuth, iaaCheck, iaaRequired, children, path, resetState } = this.props;

    if (authenticated !== null && iaaAuth !== null) {
      // If we navigate to /config, are not authenticated, have no token, go back to /
      if (tokenRequired && !authenticated && !registrationToken) {
        window.location = `/`;
      }

      // If we navigate to /config, are not authenticated, but have a token, go back to /register
      if (loginRequired && !authenticated && registrationToken) {
        window.location = `/register`;
      }

      if (loginRequired && !authenticated && !registrationToken) {
        // because the state is persisted to localStorage and we tried authenticating already
        // state.authenticated will be reloaded as false intead of null, causing a redirect loop
        resetState();
        window.location = `/login?returnUrl=${path}`;
{'fraction_non_alphanumeric': 0.10879164993978321, 'fraction_numerical': 0.0008028904054596548, 'mean_word_length': 3.2525597269624575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6030705', 'n_tokens_mistral': 685, 'n_tokens_neox': 659, 'n_words': 228}