1
0
Fork 0
mirror of https://github.com/classchartsapi/classcharts-api-js.git synced 2026-05-14 11:58:13 +00:00

feat: web support (#11)

This commit is contained in:
James Cook 2022-03-24 18:56:33 +00:00 committed by GitHub
parent f742e72b26
commit 6392ee6d1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 2122 additions and 294 deletions

View file

@ -1,4 +1,4 @@
import Undici from "undici";
import axios from "axios";
import type { GetPupilsResponse } from "./types";
import { ClasschartsClient } from "./baseClient";
@ -34,14 +34,17 @@ export class ClasschartsParentClient extends ClasschartsClient {
formData.append("password", this.password);
formData.append("recaptcha-token", "no-token-avaliable");
const request = await Undici.request(BASE_URL + "/parent/login", {
const request = await axios.request({
url: BASE_URL + "/parent/login",
method: "POST",
body: formData.toString(),
data: formData.toString(),
maxRedirects: 0,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
validateStatus: () => true,
});
if (request.statusCode != 302 || !request.headers["set-cookie"])
if (request.status != 302 || !request.headers["set-cookie"])
throw new Error("Unauthenticated: Classcharts returned an error");
const cookies = request.headers["set-cookie"];