<commit_before>import express from 'express';
import fetch from 'node-fetch';
import FormData from 'form-data';

import Firebase from 'firebase';
import { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber';


Firebase.initializeApp({
  apiKey: '<KEY>',
  authDomain: 'analoguesocial.firebaseapp.com',
  databaseURL: 'https://analoguesocial.firebaseio.com',
  storageBucket: 'analoguesocial.appspot.com',
});
const rootRef = Firebase.database().ref();


const usersRef = rootRef.child('users');

// eslint-disable-next-line new-cap
const router = express.Router();

router.post('/', (req, res, ) => {
  const phoneUtil = PhoneNumberUtil.getInstance();
  const phoneNumber = phoneUtil.parse(req.body.number, 'US');
  const tel = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);

  const envUrl = `http://${req.headers.host}/signup/token?tel=${tel}`;
  res.redirect('https://api.instagram.com/oauth/authorize/' +
  '?client_id=9b6c05b9a31643ea9abcd7651f7a6bd2' +
  '&scope=follower_list+likes+comments' +
  `&redirect_uri=${envUrl}` +
  '&response_type=code');
});

router.get('/token', (req, res) => {
  const code = req.query.code;
  const phoneUtil = PhoneNumberUtil.getInstance();
  const phoneNumber = phoneUtil.parse(req.query.tel, 'US');
  const tel = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);

  const body = new FormData();
  body.append('client_id', '9b6c05b9a31643ea9abcd7651f7a6bd2');
  body.append('client_secret', 'dc67648b48f3412b92a02e6bd817b68f');
  body.append('code', code);
  body.append('grant_type', 'authorization_code');
  body.append('redirect_uri', `http://${req.headers.host}/signup/token?tel=${tel}`);

  fetch('https://api.instagram.com/oauth/access_token', {
    method: 'POST',
    body,
  })
    .then((response) => response.json())
    .then((json) => {
      console.log(json);

      usersRef.child(tel).set(json);<commit_msg>IG signup bug (encoded chars not parsed)<commit_after>import express from 'express';
import fetch from 'node-fetch';
import FormData from 'form-data';

import Firebase from 'firebase';
import { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber';


Firebase.initializeApp({
  apiKey: '<KEY>',
  authDomain: 'analoguesocial.firebaseapp.com',
  databaseURL: 'https://analoguesocial.firebaseio.com',
  storageBucket: 'analoguesocial.appspot.com',
});
const rootRef = Firebase.database().ref();


const usersRef = rootRef.child('users');

// eslint-disable-next-line new-cap
const router = express.Router();

router.post('/', (req, res, ) => {
  const phoneUtil = PhoneNumberUtil.getInstance();
  const phoneNumber = phoneUtil.parse(req.body.number, 'US');
  const tel = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
  const igBugAvoidTel = tel.substring(1);
  const envUrl = `http://${req.headers.host}/signup/token?tel=${igBugAvoidTel}`;
  const redirectUri = 'https://api.instagram.com/oauth/authorize/' +
  '?client_id=9b6c05b9a31643ea9abcd7651f7a6bd2' +
  '&scope=follower_list+likes+comments' +
  '&response_type=code' +
  `&redirect_uri=${envUrl}`;
  res.redirect(redirectUri);
});

router.get('/token', (req, res) => {
  const code = req.query.code;
  const phoneUtil = PhoneNumberUtil.getInstance();
  const decodedTel = req.query.tel;
  const phoneNumber = phoneUtil.parse(decodedTel, 'US');
  const tel = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
  const igBugAvoidTel = tel.substring(1);
  const redirectUri = `http://${req.headers.host}/signup/token?tel=${igBugAvoidTel}`;

  const body = new FormData();
  body.append('client_id', '9b6c05b9a31643ea9abcd7651f7a6bd2');
  body.append('client_secret', '<KEY>');
  body.append('code', code);
  body.append('grant_type', 'authorization_code');
  body.append('redirect_uri', redirectUri);

  fetch('https://api.instagram.com/oauth/access_token', {
    method: 'POST',
    body,
  })
    .then((response) => response.json())
    .then((json) => {
      usersRef.child(tel).set(json);
{'fraction_non_alphanumeric': 0.16851664984863773, 'fraction_numerical': 0.026992936427850656, 'mean_word_length': 5.3036565977742445, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '4580066', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1363, 'n_words': 225}