/**
 * 华夏理财 免登
 */

'use strict';
import LightSDK from 'light-sdk/dist/index.umd'
import React from 'react';
import { observer } from 'mobx-react';
import API from '@/api';
import { md5 } from '@spark/utils';
const signKey = "wkwizzq8frj29s63isbk7wx4v9qu85nd"
@observer
class Auth extends React.Component {
  constructor(props) {
    super(props);

  }

  componentDidMount() {
    this.getUserInfo()
  }

  getUserInfo = () => {
    LightSDK.native.readData({
      key: "K_USERID",
      component_scope: "global"
    }, res => {
      console.info("LightSDK 请求结果", res)
      const uid = res.data?.result,
        redirect = `${location.origin}${CFG.index}`
      API.doAuth({
        redirect: redirect,
        uid,
        sign: md5(uid + redirect + signKey)
      }).then((res2) => {
        console.info("免登 请求结果", res2)
        if (res2.success) {
          location.replace("https:" + res2.data)
        }
      })
    })
  }

  render() {
    return (
      <div></div>
    );
  }
}

export default Auth;