Skip to content

Commit

Permalink
fix: 🐛 fix for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-kazimierczak committed Apr 22, 2022
1 parent 30b5bbb commit 8e3a9c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
11 changes: 4 additions & 7 deletions libs/api-skolplattformen/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class ApiSkolplattformen extends EventEmitter implements Api {

public async loginFreja(): Promise<FrejaLoginStatusChecker> {

await this.clearSession()
// await this.clearSession()

const loginUrl = routes.frejaLogin
const loginResponse = await this.fetch('auth-ticket', loginUrl)
Expand Down Expand Up @@ -244,10 +244,7 @@ export class ApiSkolplattformen extends EventEmitter implements Api {

try{
const url = routes.frejaReturnUrl
const session = await this.getSession(url, {
redirect: 'manual',
})
await this.fetch('freja-login-return-url', url, session)
await this.fetch('freja-login-return-url', url)
} catch(error){
console.log(JSON.stringify(error))
}
Expand All @@ -257,12 +254,12 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
const session = await this.getSession(url2, {
redirect: 'manual',
})
await this.fetch('freja-login-cookie', url2, session)
await this.fetch('freja-login-cookie', url2)
} catch(error2){
console.log(JSON.stringify(error2))
}
}

private async retrieveXsrfToken(): Promise<void> {
const url = routes.hemPage
const session = this.getRequestInit()
Expand Down
11 changes: 5 additions & 6 deletions libs/api-skolplattformen/lib/frejaLoginStatusChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ export class FrejaChecker extends EventEmitter implements FrejaLoginStatusChecke

private fetcher: Fetcher
private url: string
private session: RequestInit

private cancelled = false;

constructor(fetcher: Fetcher, token: string, session: RequestInit) {
constructor(fetcher: Fetcher, token: string) {
super();
this.fetcher = fetcher
this.session = session

this.token = token
this.url = frejaLoginStatus;
this.check();
}

async check(): Promise<void> {
const response = await this.fetcher('freja-login-status', this.url, this.session);
const response = await this.fetcher('freja-login-status', this.url);
const status = await response.text();
console.log(status)
this.emit(status);
if (!this.cancelled &&
status !== 'APPROVED' &&
Expand All @@ -30,7 +30,6 @@ export class FrejaChecker extends EventEmitter implements FrejaLoginStatusChecke
){
setTimeout(() => this.check(), 1000);
}
else console.log('APPROVED');
}

async cancel(): Promise<void> {
Expand All @@ -43,5 +42,5 @@ export class FrejaChecker extends EventEmitter implements FrejaLoginStatusChecke
fetch: Fetcher,
token: string,
session: RequestInit
): FrejaLoginStatusChecker => new FrejaChecker(fetch, token, session)
): FrejaLoginStatusChecker => new FrejaChecker(fetch, token)

0 comments on commit 8e3a9c1

Please sign in to comment.