console.log('login');

var login = document.getElementById("loginbutton");

var data = [];

var accestoken;

login.addEventListener('click', function () {
    let username = document.querySelector("#email").value;
    let password = document.querySelector("#password").value;

    var config = {
        headers: {
            'accept': 'application/json'
        }
    };

    let data = new URLSearchParams();
    data.append('username', username);
    data.append('password', password);

    axios
        .post("https://cmm.ai:8080/auth/token", data, config)
        .then((response) => {
            console.log(response);


            accestoken = response.data.access_token;

            console.log(accestoken)

            localStorage.setItem("access_token", accestoken);
            localStorage.setItem("username", username);


            alert('登入成功')

            window.location.href = "./index.html";


            //   history.go(0);
        })
        .catch((error) =>
            alert('帳號或密碼錯誤')
        );

    // if (username === 'choozmo' && password === "choozmo9") {
    //     alert('登入成功');
    //     window.location.href = "./index.html";
    // } else {
    //     alert('帳號或密碼錯誤')
    // }

});




