-
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.
Merge pull request #42 from inove-jr/25-integração-com-captcha
feat(recaptcha): implementação e validação do ReCAPTCHA v2 no formulá…
- Loading branch information
Showing
5 changed files
with
270 additions
and
8 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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
### Obtem dados de planilha passando range e sheetName | ||
GET http://localhost:3000/api/sheets?range=A:H&sheetName=projetos | ||
|
||
### Integração com Recaptcha | ||
POST http://localhost:3000/api/recaptcha | ||
Content-Type: application/json | ||
|
||
{ | ||
"token": "token" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,28 @@ | ||
import { NextRequest } from "next/server"; | ||
import axios from "axios"; | ||
import { z } from "zod"; | ||
import { env } from "@/env"; | ||
|
||
const schema = z.object({ | ||
token: z.string(), | ||
}); | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const { token } = schema.parse(await req.json()); | ||
const secretKey = env.GOOGLE_RECAPTCHA; | ||
|
||
const response = await axios.post( | ||
`https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&response=${token}`, | ||
); | ||
|
||
if (response.data.success) | ||
return Response.json(response.data, { status: 200 }); | ||
else return Response.json(response.data, { status: 400 }); | ||
} catch (error) { | ||
if (error instanceof z.ZodError) { | ||
return Response.json(error.issues, { status: 400 }); | ||
} | ||
return Response.json(error, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.