<commit_before>/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import passport from 'passport'
import Auth0Strategy from 'passport-auth0'
import {User, UserLogin, UserClaim, UserProfile} from '../data/models'
import env from '../env'

const loginName = 'auth0'
const claimType = 'urn:auth0:github'

const createUser = (profile) => {
  User.create({
    id: profile.id,
    email: profile._json.email,
    emailVerified: true,
    displayName: profile.nickname,
    picture: profile.picture,
    logins: [
      {name: loginName, key: profile.id}
    ],
    claims: [
        {type: claimType, value: profile.id}
    ],
    profile: {
      displayName: profile.nickname,
      // gender: profile._json.gender,
      picture: profile.picture,
      accessToken: profile.identities[0].access_token,
      clientID: profile._json.clientID
    }
  }, {
    include: [
      {model: UserLogin, as: 'logins'},
      {model: UserClaim, as: 'claims'},
      {model: UserProfile, as: 'profile'}
    ]
  })
}

/**
 * Sign in with auth0.
 */
passport.use(new Auth0Strategy({
  domain: env.auth0.CLIENT_DOMAIN,
  clientID: env.auth0.CLIENT_ID,
  clientSecret: env.auth0.CLIENT_SECRET,
  callbackURL: '/login/auth0/return',
  profileFields: ['name', 'email', 'link', 'locale', 'timezone'],
  passReqToCallback: true
}, (req, accessToken, refreshToken, profile, done) => {
  /* eslint-disable no-underscore-dangle */
  const authenticate = async () => {
    let user = null
    let userToken = {}

    // req.user recived from jwt cookie's token<commit_msg>Add auth0 callbackURL for env<commit_after>/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import passport from 'passport'
import Auth0Strategy from 'passport-auth0'
import {User, UserLogin, UserClaim, UserProfile} from '../data/models'
import env from '../env'

const loginName = 'auth0'
const claimType = 'urn:auth0:github'

const createUser = (profile) => {
  User.create({
    id: profile.id,
    email: profile._json.email,
    emailVerified: true,
    displayName: profile.nickname,
    picture: profile.picture,
    logins: [
      {name: loginName, key: profile.id}
    ],
    claims: [
        {type: claimType, value: profile.id}
    ],
    profile: {
      displayName: profile.nickname,
      // gender: profile._json.gender,
      picture: profile.picture,
      accessToken: profile.identities[0].access_token,
      clientID: profile._json.clientID
    }
  }, {
    include: [
      {model: UserLogin, as: 'logins'},
      {model: UserClaim, as: 'claims'},
      {model: UserProfile, as: 'profile'}
    ]
  })
}

/**
 * Sign in with auth0.
 */
let callbackURL = '/login/auth0/return'
if (process.env.NODE_ENV === 'development') {
 callbackURL = 'http://localhost:3001/login/auth0/return'
}

passport.use(new Auth0Strategy({
  domain: env.auth0.CLIENT_DOMAIN,
  clientID: env.auth0.CLIENT_ID,
  clientSecret: env.auth0.CLIENT_SECRET,
  callbackURL,
  profileFields: ['name', 'email', 'link', 'locale', 'timezone'],
  passReqToCallback: true
}, (req, accessToken, refreshToken, profile, done) => {
  /* eslint-disable no-underscore-dangle */
  const authenticate = async () => {
    let user = null
    let userToken = {}

    // req.user recived from jwt cookie's token
{'fraction_non_alphanumeric': 0.13656267104542966, 'fraction_numerical': 0.0120415982484948, 'mean_word_length': 3.3, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '7017876', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1166, 'n_words': 312}