<commit_before>import React, {Component} from 'react';
import {Link} from 'react-router';
import MainStore from '../stores/main-store';
import {browserHistory} from 'react-router';
import GoogleLogin from 'react-google-login';
import Translate from 'react-translate-component';

class Auth extends Component {
  constructor(props, context) {
    super(props, context);

    this.state = {};
  }

  componentDidMount() {
    this.loadGoogleSignIn()
  }

  async loadGoogleSignIn() {
    const url = '/api/auth/google_client_id';
    const response = await fetch(url);
    const json = await response.json();
    this.setState({google_client_id: json.google_client_id});
  }

  async onGoogleResponse(googleResponse) {
    const url = '/api/auth';
    const token = googleResponse.tokenId;
    const body = JSON.stringify({token: token});

    const response = await fetch(url, {method: 'POST', body: body, credentials: 'same-origin'});
    const json = await response.json();

    MainStore.setUser(json);

    browserHistory.push('/');
  }

  render() {
    return (
        <div className="u-center-block__content">
          <div className="o-form-element" style={{textAlign: 'center'}}>
            {this.state.google_client_id &&
              <Translate
                component={GoogleLogin}
                clientId={this.state.google_client_id}
                attributes={{buttonText: "auth.log_in_with_google"}}
                fetchBasicProfile={true}
                autoLoad={true}
                onSuccess={this.onGoogleResponse} />
            }
          </div>
          <div className="o-form-element">
            <Translate content="auth.disclaimer"/> <Translate component={Link} className="c-link" content="auth.disclaimer_link" to="/terms#contributor"/><br />
            <Translate content="auth.privacy_disclaimer"/> <Translate component={Link} className="c-link" content="auth.privacy_disclaimer_link" to="/terms#privacy"/>.
          </div>
        </div>
    )
  }
}

export default Auth<commit_msg>Redirects to user profile after logging-in<commit_after>import React, {Component} from 'react';
import {Link} from 'react-router';
import MainStore from '../stores/main-store';
import {browserHistory} from 'react-router';
import GoogleLogin from 'react-google-login';
import Translate from 'react-translate-component';

class Auth extends Component {
  constructor(props, context) {
    super(props, context);

    this.state = {};
  }

  componentDidMount() {
    this.loadGoogleSignIn()
  }

  async loadGoogleSignIn() {
    const url = '/api/auth/google_client_id';
    const response = await fetch(url);
    const json = await response.json();
    this.setState({google_client_id: json.google_client_id});
  }

  async onGoogleResponse(googleResponse) {
    const url = '/api/auth';
    const token = googleResponse.tokenId;
    const body = JSON.stringify({token: token});

    const response = await fetch(url, {method: 'POST', body: body, credentials: 'same-origin'});
    const json = await response.json();

    MainStore.setUser(json);

    browserHistory.push(`/user/${json.userid}`);
  }

  render() {
    return (
        <div className="u-center-block__content">
          <div className="o-form-element" style={{textAlign: 'center'}}>
            {this.state.google_client_id &&
              <Translate
                component={GoogleLogin}
                clientId={this.state.google_client_id}
                attributes={{buttonText: "auth.log_in_with_google"}}
                fetchBasicProfile={true}
                autoLoad={true}
                onSuccess={this.onGoogleResponse} />
            }
          </div>
          <div className="o-form-element">
            <Translate content="auth.disclaimer"/> <Translate component={Link} className="c-link" content="auth.disclaimer_link" to="/terms#contributor"/><br />
            <Translate content="auth.privacy_disclaimer"/> <Translate component={Link} className="c-link" content="auth.privacy_disclaimer_link" to="/terms#privacy"/>.
          </div>
        </div>
    )
  }
}

export default Auth
{'fraction_non_alphanumeric': 0.13791423001949318, 'fraction_numerical': 0.0, 'mean_word_length': 2.981571290009699, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1051042', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1164, 'n_words': 240}