mirror of
https://github.com/classchartsapi/classcharts-api-js.git
synced 2026-05-14 11:58:13 +00:00
fix: Parent client Login (#36)
This commit is contained in:
parent
39e7adf53f
commit
dea1a00f13
1 changed files with 6 additions and 5 deletions
|
|
@ -39,7 +39,7 @@ export class ParentClient extends BaseClient {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
credentials: undefined,
|
redirect: "manual",
|
||||||
});
|
});
|
||||||
if (response.status != 302 || !response.headers.has("set-cookie")) {
|
if (response.status != 302 || !response.headers.has("set-cookie")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
@ -56,19 +56,20 @@ export class ParentClient extends BaseClient {
|
||||||
const sessionID = JSON.parse(
|
const sessionID = JSON.parse(
|
||||||
String(sessionCookies["parent_session_credentials"]),
|
String(sessionCookies["parent_session_credentials"]),
|
||||||
);
|
);
|
||||||
super.sessionId = sessionID.session_id;
|
this.sessionId = sessionID.session_id;
|
||||||
this.pupils = await this.getPupils();
|
this.pupils = await this.getPupils();
|
||||||
if (!this.pupils) throw new Error("Account has no pupils attached");
|
if (!this.pupils) throw new Error("Account has no pupils attached");
|
||||||
super.studentId = this.pupils[0].id;
|
this.studentId = this.pupils[0].id;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get a list of pupils connected to this parent's account
|
* Get a list of pupils connected to this parent's account
|
||||||
* @returns an array of Pupils connected to this parent's account
|
* @returns an array of Pupils connected to this parent's account
|
||||||
*/
|
*/
|
||||||
async getPupils(): Promise<GetPupilsResponse> {
|
async getPupils(): Promise<GetPupilsResponse> {
|
||||||
return await super.makeAuthedRequest(super.API_BASE + "/pupils", {
|
const response = await this.makeAuthedRequest(this.API_BASE + "/pupils", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
|
return response.data;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Selects a pupil to be used with API requests
|
* Selects a pupil to be used with API requests
|
||||||
|
|
@ -82,7 +83,7 @@ export class ParentClient extends BaseClient {
|
||||||
for (let i = 0; i < pupils.length; i++) {
|
for (let i = 0; i < pupils.length; i++) {
|
||||||
const pupil = pupils[i];
|
const pupil = pupils[i];
|
||||||
if (pupil.id == pupilId) {
|
if (pupil.id == pupilId) {
|
||||||
super.studentId = pupil.id;
|
this.studentId = pupil.id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue