File tree Expand file tree Collapse file tree 9 files changed +504
-429
lines changed Expand file tree Collapse file tree 9 files changed +504
-429
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,9 @@ const aj = arcjet
30
30
// Protect the sensitive actions e.g. login, signup, etc with Arcjet
31
31
const ajProtectedPOST = async ( req : NextRequest ) => {
32
32
// Next.js 15 doesn't provide the IP address in the request object so we use
33
- // the Arcjet utility package to parse the headers and find it
34
- const userIp = ip ( req ) ;
33
+ // the Arcjet utility package to parse the headers and find it. If we're
34
+ // running in development mode, we'll use a local IP address.
35
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
35
36
const decision = await aj . protect ( req , { fingerprint : userIp } ) ;
36
37
37
38
if ( decision . isDenied ( ) ) {
Original file line number Diff line number Diff line change @@ -16,8 +16,9 @@ const aj = arcjet.withRule(
16
16
17
17
export async function GET ( req : NextRequest ) {
18
18
// Next.js 15 doesn't provide the IP address in the request object so we use
19
- // the Arcjet utility package to parse the headers and find it
20
- const userIp = ip ( req ) ;
19
+ // the Arcjet utility package to parse the headers and find it. If we're
20
+ // running in development mode, we'll use a local IP address.
21
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
21
22
// The protect method returns a decision object that contains information
22
23
// about the request.
23
24
const decision = await aj . protect ( req , { fingerprint : userIp } ) ;
Original file line number Diff line number Diff line change @@ -26,8 +26,9 @@ const aj = arcjet
26
26
27
27
export async function GET ( req : NextRequest ) {
28
28
// Next.js 15 doesn't provide the IP address in the request object so we use
29
- // the Arcjet utility package to parse the headers and find it
30
- const userIp = ip ( req ) ;
29
+ // the Arcjet utility package to parse the headers and find it. If we're
30
+ // running in development mode, we'll use a local IP address.
31
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
31
32
// The protect method returns a decision object that contains information
32
33
// about the request.
33
34
const decision = await aj . protect ( req , { fingerprint : userIp } ) ;
Original file line number Diff line number Diff line change @@ -46,8 +46,9 @@ export async function POST(req: NextRequest) {
46
46
console . log ( "Session: " , session ) ;
47
47
48
48
// Next.js 15 doesn't provide the IP address in the request object so we use
49
- // the Arcjet utility package to parse the headers and find it
50
- const userIp = ip ( req ) ;
49
+ // the Arcjet utility package to parse the headers and find it. If we're
50
+ // running in development mode, we'll use a local IP address.
51
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
51
52
52
53
// Use the user ID if the user is logged in, otherwise use the IP address
53
54
const fingerprint = session ?. user ?. id ?? userIp ;
Original file line number Diff line number Diff line change @@ -26,8 +26,9 @@ const aj = arcjet
26
26
27
27
export async function POST ( req : NextRequest ) {
28
28
// Next.js 15 doesn't provide the IP address in the request object so we use
29
- // the Arcjet utility package to parse the headers and find it
30
- const userIp = ip ( req ) ;
29
+ // the Arcjet utility package to parse the headers and find it. If we're
30
+ // running in development mode, we'll use a local IP address.
31
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
31
32
// The protect method returns a decision object that contains information
32
33
// about the request.
33
34
const decision = await aj . protect ( req , { fingerprint : userIp } ) ;
Original file line number Diff line number Diff line change @@ -57,8 +57,9 @@ export async function POST(req: NextRequest) {
57
57
const { email } = data . data ;
58
58
59
59
// Next.js 15 doesn't provide the IP address in the request object so we use
60
- // the Arcjet utility package to parse the headers and find it
61
- const userIp = ip ( req ) ;
60
+ // the Arcjet utility package to parse the headers and find it. If we're
61
+ // running in development mode, we'll use a local IP address.
62
+ const userIp = process . env . NODE_ENV === "development" ? "127.0.0.1" : ip ( req ) ;
62
63
// The protect method returns a decision object that contains information
63
64
// about the request.
64
65
const decision = await aj . protect ( req , { fingerprint : userIp , email } ) ;
Original file line number Diff line number Diff line change 2
2
/// <reference types="next/image-types/global" />
3
3
4
4
// NOTE: This file should not be edited
5
- // see https://nextjs.org/docs/app/building-your-application/configuring /typescript for more information.
5
+ // see https://nextjs.org/docs/app/api-reference/config /typescript for more information.
You can’t perform that action at this time.
0 commit comments