generated from hoonsubin/discord-bot-starter
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added reCAPCHA verification tool (#39)
* feat: added google-recaptcha verification * fix: updated isStagingUrl var
- Loading branch information
1 parent
1d43953
commit 5ae170c
Showing
7 changed files
with
285 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'google-recaptcha'; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './addNumber'; | ||
export * from './calculation'; | ||
export * from './recaptcha'; |
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,23 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import GoogleRecaptcha from 'google-recaptcha'; | ||
|
||
export const verifyRecaptcha = async ({ | ||
recaptchaResponse, | ||
recaptchaSecret, | ||
}: { | ||
recaptchaResponse: string; | ||
recaptchaSecret: string; | ||
}): Promise<boolean> => { | ||
const googleRecaptcha = new GoogleRecaptcha({ secret: recaptchaSecret }); | ||
if (!recaptchaResponse) throw Error('invalid recaptcha'); | ||
return await new Promise<boolean>(async (resolve) => { | ||
googleRecaptcha.verify({ response: recaptchaResponse }, (error: Error) => { | ||
if (error) { | ||
throw Error('invalid recaptcha'); | ||
} else { | ||
resolve(true); | ||
} | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.