-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clerk-js): Block /tokens requests until fraud detection completes (…
- Loading branch information
1 parent
afcc517
commit ba97f62
Showing
2 changed files
with
34 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* TODO: @nikos Move captcha and fraud detection logic to this class | ||
*/ | ||
class FraudProtectionService { | ||
private inflightRequest: Promise<unknown> | null = null; | ||
|
||
public async execute<T extends () => Promise<any>>(cb: T): Promise<Awaited<ReturnType<T>>> { | ||
if (this.inflightRequest) { | ||
await this.inflightRequest; | ||
} | ||
|
||
const prom = cb(); | ||
this.inflightRequest = prom; | ||
return prom.then(res => { | ||
this.inflightRequest = null; | ||
return res; | ||
}); | ||
} | ||
|
||
public blockUntilReady() { | ||
return this.inflightRequest ? this.inflightRequest.then(() => null) : Promise.resolve(); | ||
} | ||
} | ||
|
||
export const fraudProtection = new FraudProtectionService(); |
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