<commit_before>import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';

const IS_LOCAL = process.env.NODE_ENV === 'development' ||
  process.env.NODE_ENV === 'test';

const localFirebaseConfig_ = {
  apiKey: "<KEY>",
  authDomain: "barnard-project.firebaseapp.com",
  databaseURL: "https://barnard-project.firebaseio.com",
  projectId: "barnard-project",
  storageBucket: "barnard-project.appspot.com",
  messagingSenderId: "929114075380",
  appId: "1:929114075380:web:3ab89bf036919331262ea1",
  measurementId: "G-4X4KQ1ZF68"
};

const config = require('../config.json');

const firebaseConfig_ = IS_LOCAL ? localFirebaseConfig_ : config.firebase_config; // eslint-disable-line

const EMPTY_APP_SETTINGS = {
  organization_name: "",
  organization_url: "",
  primary_language: "",
  privacy_policy: "",
  translation_language: ""
};
class AuthUtils {
  constructor() {
    // to be overwritten by firestore values
    AuthUtils.app_settings = EMPTY_APP_SETTINGS;
    if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig_);
      AuthUtils.fsdb = firebase.firestore();
      AuthUtils.app_url = "https://" + firebaseConfig_.projectId + ".appspot.com";
      AuthUtils.app_url_contributor = "https://" + firebaseConfig_.projectId + ".firebaseapp.com";
    }
    this.provider_ = new firebase.auth.GoogleAuthProvider();
  }

  static setAppSettings(app_settings){
    AuthUtils.app_settings = app_settings;
  }
  static getAppSettings(){
    const appSettings = AuthUtils.app_settings;
    if (appSettings.primary_language && appSettings.organization_url && appSettings.organization_name){
        return AuthUtils.app_settings;
    }else{
        return null;
    }
  }
  static getPrimaryLanguage(){
    if (AuthUtils.app_settings){
        return AuthUtils.app_settings.primary_language;
    }else{
        return EMPTY_APP_SETTINGS;
    }
  }
  async signInWithPopup() {
    return await firebase.auth().signInWithPopup(this.provider_);
  }

  static async signOut() {
    return await firebase.auth().signOut();
  }

  static getUser() {
    return AuthUtils.user;
  }

  static setUser(user) {
    AuthUtils.user = user;
  }
  static getUserType(user) {
    return AuthUtils.usertype;
  }
  static setUserType(user) {
    AuthUtils.usertype = user;
  }

  static async getAuthHeader() {
    if (!AuthUtils.user) {
      return 'Bearer ';
    }

    if (AuthUtils.idToken) {
      return `Bearer ${AuthUtils.idToken}`;
    }

    const idToken = await AuthUtils.user.getIdToken();
    AuthUtils.idToken = idToken;

    return `Bearer ${idToken}`;
  }

  getFirebaseAuth() {
    return firebase.auth();
  }
}


export default AuthUtils;
<commit_msg>Attempt to resolve intermittent 403 due to expired token<commit_after>import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';

const IS_LOCAL = process.env.NODE_ENV === 'development' ||
  process.env.NODE_ENV === 'test';

const localFirebaseConfig_ = {
  apiKey: "<KEY>",
  authDomain: "barnard-project.firebaseapp.com",
  databaseURL: "https://barnard-project.firebaseio.com",
  projectId: "barnard-project",
  storageBucket: "barnard-project.appspot.com",
  messagingSenderId: "929114075380",
  appId: "1:929114075380:web:3ab89bf036919331262ea1",
  measurementId: "G-4X4KQ1ZF68"
};

const config = require('../config.json');

const firebaseConfig_ = IS_LOCAL ? localFirebaseConfig_ : config.firebase_config; // eslint-disable-line

const EMPTY_APP_SETTINGS = {
  organization_name: "",
  organization_url: "",
  primary_language: "",
  privacy_policy: "",
  translation_language: ""
};
class AuthUtils {
  constructor() {
    // to be overwritten by firestore values
    AuthUtils.app_settings = EMPTY_APP_SETTINGS;
    if (!firebase.apps.length) {
      firebase.initializeApp(firebaseConfig_);
      AuthUtils.fsdb = firebase.firestore();
      AuthUtils.app_url = "https://" + firebaseConfig_.projectId + ".appspot.com";
      AuthUtils.app_url_contributor = "https://" + firebaseConfig_.projectId + ".firebaseapp.com";
    }
    this.provider_ = new firebase.auth.GoogleAuthProvider();
  }

  static setAppSettings(app_settings){
    AuthUtils.app_settings = app_settings;
  }
  
  static getAppSettings(){
    const appSettings = AuthUtils.app_settings;
    if (appSettings.primary_language && appSettings.organization_url && appSettings.organization_name){
        return AuthUtils.app_settings;
    }else{
        return null;
    }
  }
  static getPrimaryLanguage(){
    if (AuthUtils.app_settings){
        return AuthUtils.app_settings.primary_language;
    }else{
        return EMPTY_APP_SETTINGS;
    }
  }
  async signInWithPopup() {
    return await firebase.auth().signInWithPopup(this.provider_);
  }

  static async signOut() {
    return await firebase.auth().signOut();
  }

  static getUser() {
    return AuthUtils.user;
  }

  static setUser(user) {
    AuthUtils.user = user;
  }
  
  static getUserType(user) {
    return AuthUtils.usertype;
  }
  
  static setUserType(user) {
    AuthUtils.usertype = user;
  }

  static async getAuthHeader() {
    if (!AuthUtils.user) {
      return 'Bearer ';
    }
    const idToken = await AuthUtils.user.getIdToken();
    return `Bearer ${idToken}`;
  }

  getFirebaseAuth() {
    return firebase.auth();
  }
}

export default AuthUtils;

{'fraction_non_alphanumeric': 0.12331586826347306, 'fraction_numerical': 0.017776946107784432, 'mean_word_length': 3.7511111111111113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, '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': '5073532', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1764, 'n_words': 313}