<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import {
  formatUser,
  getCurrentUserListener
} from 'authentication/user'
import {
  replaceUrl,
  verifyEmailURL,
  enterUsernameURL,
  goToLogin
} from 'navigation/navigation'

// Get the authenticated user and, if the user is authenticated,
// add the user's ID to the `variables` prop. By default, redirect
// to the authentication view if the user is not authenticated.
// TODO: change to a higher-order component:
// https://reactjs.org/docs/higher-order-components.html
class AuthUserComponent extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      userId: null
    }
  }

  componentDidMount () {
    // Store unsubscribe function.
    // https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged
    this.authListenerUnsubscribe = getCurrentUserListener()
      .onAuthStateChanged((user) => {
        if (user) {
          const formattedUser = formatUser(user)
          this.checkUserAuth(formattedUser)
        } else {
          this.checkUserAuth(user)
        }
      })
  }

  componentWillUnmount () {
    if (typeof this.authListenerUnsubscribe === 'function') {
      this.authListenerUnsubscribe()
    }
  }

  checkUserAuth (user) {
    // If the user is authed, set the ID in state.
    if (user && user.id) {
      this.setState({
        userId: user.id
      })
    }

    // Stay on this page if it's okay to render children
    // regardless on the user auth status.
    if (this.props.allowUnauthedRender) {
      return
    }

    // If the user is not fully logged in, redirect to the
    // appropriate auth page.
    // User is not logged in.
    if (!user || !user.id) {
      goToLogin()
    // User is logged in but their email is not verified.<commit_msg>Redirect the user to an error message if they’re missing an email address.<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import {
  formatUser,
  getCurrentUserListener
} from 'authentication/user'
import {
  replaceUrl,
  missingEmailMessageURL,
  verifyEmailURL,
  enterUsernameURL,
  goToLogin
} from 'navigation/navigation'

// Get the authenticated user and, if the user is authenticated,
// add the user's ID to the `variables` prop. By default, redirect
// to the authentication view if the user is not authenticated.
// TODO: change to a higher-order component:
// https://reactjs.org/docs/higher-order-components.html
class AuthUserComponent extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      userId: null
    }
  }

  componentDidMount () {
    // Store unsubscribe function.
    // https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged
    this.authListenerUnsubscribe = getCurrentUserListener()
      .onAuthStateChanged((user) => {
        if (user) {
          const formattedUser = formatUser(user)
          this.checkUserAuth(formattedUser)
        } else {
          this.checkUserAuth(user)
        }
      })
  }

  componentWillUnmount () {
    if (typeof this.authListenerUnsubscribe === 'function') {
      this.authListenerUnsubscribe()
    }
  }

  checkUserAuth (user) {
    // If the user is authed, set the ID in state.
    if (user && user.id) {
      this.setState({
        userId: user.id
      })
    }

    // Stay on this page if it's okay to render children
    // regardless on the user auth status.
    if (this.props.allowUnauthedRender) {
      return
    }

    // If the user is not fully logged in, redirect to the
    // appropriate auth page.
    // User is not logged in.
    if (!user || !user.id) {
      goToLogin()
    // If the user does not have an email address, show a message
    // asking them to sign in with a different method.
    } else if (!user.email) {
      replaceUrl(missingEmailMessageURL)
    // User is logged in but their email is not verified.
{'fraction_non_alphanumeric': 0.09855586521408664, 'fraction_numerical': 0.0, 'mean_word_length': 2.6623376623376624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '366309', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1134, 'n_words': 357}