import { View, Button } from "@tarojs/components";
import { useEffect } from "react";
import { WeWork } from "../../utils/WeWork";
import { api } from "../../utils/Api";

const Login = () => {
  useEffect(() => {
    WeWork.init("wwauth994c6f0045619f58000022");
  }, []);

  return (
    <View>
      <Button
        onClick={async () => {
          try {
            const code = await WeWork.login(
              "wx994c6f0045619f58",
              "1000022",
              "wwauth994c6f0045619f58000022"
            );
            console.log(code);
            const userInfo = await api.getUserInfo(code);
            console.log(userInfo);
          } catch (error) {
            console.log(error);
          }
        }}
      >
        登录
      </Button>
    </View>
  );
};

export default Login;
