import { fetch } from "https://esm.town/v/std/fetch";
export let pelotonWorkouts = async (credentials) => {
let loginResponse = await fetch('https://api.onepeloton.com/auth/login', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(credentials)
})
let cookie = loginResponse.headers.get('set-cookie')
let {user_id} = await loginResponse.json()
let workouts = await fetch(`https://api.onepeloton.com/api/user/${user_id}/workouts?=peloton.ride&limit=10&page=0&sort_by=-created`, {
method: 'get',
headers: {'Content-Type': 'application/json', 'Cookie': cookie},
})
return workouts.json()
}