const API = "http://10.10.1.112:5000"

export async function authLogin(username, password) {
  try {
    const res = await fetch(`${API}/login`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        username,
        password
      })
    })

    return await res.json()

  } catch (err) {
    return {
      success: false,
      message: "Server error"
    }
  }
}

export async function authRegister(nama, username, password) {
  try {
    const res = await fetch(`${API}/register`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        nama,
        username,
        password
      })
    })

    return await res.json()

  } catch (err) {
    return {
      success: false,
      message: "Server error"
    }
  }
}