import { Dispatch } from 'redux'; const auth = { 'login': () => (dispatch: Dispatch) => { dispatch({ type: 'authLoad', loading: true, }) fetch("https://www.ingress.com/intel", { "credentials": "include", "referrer": "https://intel.ingress.com/" }) .then(r => r.text()) .then(t => { const s1 = t.match(/gen_dashboard_(.+?)\.js/) if (s1 == null) { throw new Error("V not found") } const v = s1[1] const s2 = t.match(/var PLAYER = (.+?)\;\n/) if (s2 == null) { throw new Error("user not found") } const user = JSON.parse(s2[1]) const s3 = t.match(/\/) if (s3 == null) { throw new Error("csrf not found") } const csrf = s3[1] return { v, user, csrf } // }) // .then(({ v, user }) => { // return CookieManager.get("https://intel.ingress.com") // .then(cookies => { // const csrf = cookies['csrftoken'] // return { v, csrf, user } // }) }).then(({ v, csrf, user }) => dispatch({ type: 'authSet', v, csrf, user }) ) } } export default auth