/**
 * next-auth.providers.js Example
 *
 * This file returns a simple array of oAuth Provider objects for NextAuth.
 *
 * This example returns an array based on what environment variables are set,
 * with explicit support for Facebook, Google and Twitter, but it can be used
 * to add strategies for other oAuth providers.
 *
 * Environment variables for this example:
 *
 * FACEBOOK_ID=
 * FACEBOOK_SECRET=
 * GOOGLE_ID=
 * GOOGLE_SECRET=
 * TWITTER_KEY=
 * TWITTER_SECRET=
 *
 * If you wish, you can put these in a `.env` to seperate your environment 
 * specific configuration from your code.
 **/

// Load environment variables from a .env file if one exists
require('dotenv').load()

module.exports = () => {
  let providers = []

    providers.push({
      providerName: 'Facebook',
      providerOptions: {
        scope: ['email', 'public_profile']
      },
      Strategy: require('passport-facebook').Strategy,
      strategyOptions: {
        clientID: process.env.NODE_ENV === 'production' ? process.env.TT_FACEBOOK_ID : process.env.FACEBOOK_ID,
        clientSecret: process.env.NODE_ENV === 'production' ? process.env.TT_FACEBOOK_SECRET : process.env.FACEBOOK_SECRET,
        profileFields: ['id', 'displayName', 'email', 'link']
      },
      getProfile(profile) {
        // Normalize profile into one with {id, name, email} keys
        return {
          id: profile.id,
          name: profile.displayName,
          email: profile._json.email
        }
      }
    })
  

    providers.push({
      providerName: 'Linkedin',
      providerOptions: {
        scope: ['r_emailaddress', 'r_basicprofile']
      },
      Strategy: require('@sokratis/passport-linkedin-oauth2').Strategy,
      strategyOptions: {
        clientID: process.env.NODE_ENV === 'production' ? process.env.TT_LINKEDIN_ID : process.env.LINKEDIN_ID,
        clientSecret: process.env.NODE_ENV === 'production' ? process.env.TT_LINKEDIN_SECRET : process.env.LINKEDIN_SECRET,
        profileFields: ['r_emailaddress', 'r_basicprofile']
      },
      getProfile(profile) {
        // Normalize profile into one with {id, name, email} keys
        return {
          id: profile.id,
          // name: profile.displayName,
          // email: profile._json.email
        }
      }
    })
  
  
  return providers
}