Skip to content

Commit ce1cacb

Browse files
fix: fix possible logical flaw with asynchronous token validaton
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 1074597 commit ce1cacb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/services/readwise-api.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ export default class ReadwiseApi {
6464
* @returns {Promise<boolean>} - Returns a promise that resolves to a boolean indicating if the token is valid
6565
*/
6666
async hasValidToken(): Promise<boolean> {
67-
if (this.validToken === undefined) {
68-
this.validateToken().then((value) => {
69-
this.validToken = value;
70-
return value;
71-
});
72-
}
73-
return this.validToken;
74-
}
67+
async hasValidToken(): Promise<boolean> {
68+
if (this.validToken === undefined) {
69+
this.validToken = await this.validateToken();
70+
}
71+
return this.validToken;
72+
}
7573

7674
/**
7775
* Checks if the token is valid by making a request to the Readwise API

0 commit comments

Comments
 (0)