<commit_before>import hello from 'hellojs'
import Cookies from 'js-cookie'
import {action} from 'mobx'

const LOGIN_URL = `${process.env.API_URL}/v1.1/account/auth/`
const REGISTER_URL = `${process.env.API_URL}/v1.1/account/register/`

export default class Auth {
  constructor (props) {
    this.initHello()
  }

  @action.bound rebuildSession () {
    this.store.isLoggedIn = Boolean(Cookies.get('logged_in'))
  }

  @action.bound async login (credentials) {
    const {request} = this.services
    const {messages} = this.stores

    messages.delete('auth.login')

    try {
      const res = await request.post(LOGIN_URL, credentials)

      this.redirectToDashboard(res.data.account_key)
    } catch (err) {
      const {data} = err.response

      messages.set('auth.login', data)
    }
  }

  @action.bound async register (credentials) {
    const {request} = this.services
    const {messages} = this.stores

    messages.delete('auth.register')

    try {
      const res = await request.post(REGISTER_URL, credentials)

      this.redirectToDashboard(res.data.account_key, true)
    } catch (err) {
      const {data} = err.response

      messages.set('auth.register', data)
    }
  }

  @action.bound socialAuth (network) {
    const {messages} = this.stores
    const {request} = this.services

    this.hello(network).login(async social => {
      const {access_token} = social.authResponse

      if (social.network === 'google') {
        social.network = 'google-oauth2'
      }

      try {
        const res = await request.post(`${LOGIN_URL}${social.network}/`, {access_token})

        this.redirectToDashboard(res.data.account_key, res.data.created)
      } catch (err) {
        messages.set('auth.social', err.message)
      }
    }, err => {
      messages.set('auth.social', err)
    })
  }

  redirectToDashboard = (token, signUpMode = false) => {
    let redirectUrl = `${process.env.DASHBOARD_URL}/#/login?token=${token}`

    if (signUpMode) {
      redirectUrl = `${process.env.DASHBOARD_URL}#/setup?token=${token}&signUpMode=${signUpMode}`
    }

    window.location.href = redirectUrl
  }

  initHello () {
    const credentials = {
      facebook: process.env.HELLO_FACEBOOK,
      google: process.env.HELLO_GOOGLE,
      github: process.env.HELLO_GITHUB
    }

    const options = {
      scope: 'email',
      redirect_uri: process.env.HELLO_REDIRECT_URI
    }

    hello.init(credentials, options)

    this.hello = hello.bind(hello)
  }
}<commit_msg>fix(services): invalid social registration url<commit_after>import hello from 'hellojs'
import Cookies from 'js-cookie'
import {action} from 'mobx'

const LOGIN_URL = `${process.env.API_URL}/v1.1/account/auth/`
const REGISTER_URL = `${process.env.API_URL}/v1.1/account/register/`

export default class Auth {
  constructor (props) {
    this.initHello()
  }

  @action.bound rebuildSession () {
    this.store.isLoggedIn = Boolean(Cookies.get('logged_in'))
  }

  @action.bound async login (credentials) {
    const {request} = this.services
    const {messages} = this.stores

    messages.delete('auth.login')

    try {
      const res = await request.post(LOGIN_URL, credentials)

      this.redirectToDashboard(res.data.account_key)
    } catch (err) {
      const {data} = err.response

      messages.set('auth.login', data)
    }
  }

  @action.bound async register (credentials) {
    const {request} = this.services
    const {messages} = this.stores

    messages.delete('auth.register')

    try {
      const res = await request.post(REGISTER_URL, credentials)

      this.redirectToDashboard(res.data.account_key, true)
    } catch (err) {
      const {data} = err.response

      messages.set('auth.register', data)
    }
  }

  @action.bound socialAuth (network) {
    const {messages} = this.stores
    const {request} = this.services

    this.hello(network).login(async social => {
      const {access_token} = social.authResponse

      if (social.network === 'google') {
        social.network = 'google-oauth2'
      }

      try {
        const res = await request.post(`${LOGIN_URL}${social.network}/`, {access_token})

        this.redirectToDashboard(res.data.account_key, res.data.created)
      } catch (err) {
        messages.set('auth.social', err.message)
      }
    }, err => {
      messages.set('auth.social', err)
    })
  }

  redirectToDashboard = (token, signUpMode = false) => {
    let redirectUrl = `${process.env.DASHBOARD_URL}/#/login?token=${token}`

    if (signUpMode) {
      redirectUrl += `&signUpMode=${signUpMode}`
    }

    window.location.href = redirectUrl
  }

  initHello () {
    const credentials = {
      facebook: process.env.HELLO_FACEBOOK,
      google: process.env.HELLO_GOOGLE,
      github: process.env.HELLO_GITHUB
    }

    const options = {
      scope: 'email',
      redirect_uri: process.env.HELLO_REDIRECT_URI
    }

    hello.init(credentials, options)

    this.hello = hello.bind(hello)
  }
}
{'fraction_non_alphanumeric': 0.13588709677419356, 'fraction_numerical': 0.0020161290322580645, 'mean_word_length': 2.9435612082670906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '789551', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1611, 'n_words': 296}