import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export async function GetPelotonUser(
req: express.Request,
res: express.Response,
) {
let response = await fetch("https://api.onepeloton.com/auth/login", {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({
username_or_email: process.env.peloLogin,
password: process.env.peloPass,
}),
});
const session = await response.json();
let userResponse = await fetch(
`https://api.onepeloton.com/api/user/${session["user_id"]}`,
{
method: "GET",
mode: "no-cors",
credentials: "include",
headers: {
"Content-Type": "application/json",
cookie: `peloton_session_id=${session["session_id"]};`,
"peloton-platform": "web",
},
},
);
const user = await userResponse.json();
res.send(user);
}