forked from kolplattformen/skolplattformen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
948568d
commit d9c62a6
Showing
10 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { EventEmitter } from 'events'; | ||
import { frejaLoginStatus } from './routes'; | ||
import { Fetcher, FrejaLoginStatusChecker } from '@skolplattformen/api'; | ||
export class FrejaChecker extends EventEmitter implements FrejaLoginStatusChecker { | ||
public token: string; | ||
|
||
private fetcher: Fetcher; | ||
private url: string; | ||
|
||
private cancelled = false; | ||
|
||
constructor(fetcher: Fetcher, token: string) { | ||
super(); | ||
this.fetcher = fetcher | ||
|
||
this.token = token | ||
this.url = frejaLoginStatus; | ||
this.check(); | ||
} | ||
|
||
async check(): Promise<void> { | ||
const response = await this.fetcher('freja-login-status', this.url); | ||
const status = await response.text(); | ||
this.emit(status); | ||
if (!this.cancelled && | ||
status !== 'APPROVED' && | ||
// status !== 'ERROR!' && | ||
status !== 'CANCELLED' | ||
){ | ||
setTimeout(() => this.check(), 1000); | ||
} | ||
else console.log('APPROVED'); | ||
} | ||
|
||
async cancel(): Promise<void> { | ||
this.cancelled = true; | ||
} | ||
} | ||
|
||
|
||
export const checkStatus = ( | ||
fetch: Fetcher, | ||
token: string, | ||
): FrejaLoginStatusChecker => new FrejaChecker(fetch, token) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters