-
Notifications
You must be signed in to change notification settings - Fork 0
fix: attach form rules and stop dummy Arcjet keys #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,11 @@ | ||
| import arcjetNextjs, { detectBot } from "@arcjet/next"; | ||
|
|
||
| // Get your site key from https://console.arcjet.com | ||
| // and set it as an environment variable rather than hard coding. | ||
| // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables | ||
| let key = process.env.ARCJET_KEY; | ||
| if (!key) { | ||
| // Normally we would throw an error here, but for the sake of the example | ||
| // application we will just log a warning and use a dummy key. | ||
|
|
||
| console.warn("Warning: ARCJET_KEY environment variable is not set."); | ||
| console.warn( | ||
| "Please set it to your Arcjet site key to enable bot protection.", | ||
| ); | ||
| key = "arcjet_dummykey"; | ||
| } | ||
|
|
||
| // Create a base Arcjet instance for use by each handler | ||
| export const arcjet = arcjetNextjs({ | ||
| key, | ||
| // Get your site key from https://console.arcjet.com | ||
| // and set it as an environment variable rather than hard coding. | ||
| // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables | ||
| key: process.env.ARCJET_KEY!, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as |
||
| rules: [ | ||
| detectBot({ | ||
| mode: "LIVE", // will block requests. Use "DRY_RUN" to log only | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,20 +8,11 @@ import arcjet, { | |
| } from "@arcjet/next"; | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| // Get your site key from https://console.arcjet.com | ||
| // and set it as an environment variable rather than hard coding. | ||
| // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables | ||
| let key = process.env.ARCJET_KEY; | ||
| if (!key) { | ||
| // Normally we would throw an error here, but for the sake of the example | ||
| // application we will just log a warning and use a dummy key. | ||
| console.warn("Warning: ARCJET_KEY environment variable is not set."); | ||
| key = "arcjet_dummykey"; | ||
| } | ||
|
|
||
| const aj = arcjet({ | ||
| // Get your site key from https://console.arcjet.com | ||
| key, | ||
| // and set it as an environment variable rather than hard coding. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note as the other Next.js examples — |
||
| // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables | ||
| key: process.env.ARCJET_KEY!, | ||
| rules: [ | ||
| // Shield protects your app from common attacks e.g. SQL injection | ||
| shield({ mode: "LIVE" }), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,9 @@ RUN npm ci | |
|
|
||
| COPY . . | ||
|
|
||
| # Note: Nuxt requires `ARCJET_KEY` to be set during build. Here we set it to a | ||
| # dummy value if not set to allow builds to succeed. | ||
| ENV ARCJET_KEY=${ARCJET_KEY:-ajkey_dummy} | ||
|
|
||
| # NOTE: Have to run postinstall as it handles automatic import resolution | ||
| RUN npm run postinstall && npm run build | ||
| # Nuxt requires `ARCJET_KEY` at build time. Keep the placeholder on this RUN | ||
| # only — do not persist it as a runtime ENV or the image ships a dummy key. | ||
| ARG ARCJET_KEY=ajkey_yourkey | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default |
||
| RUN ARCJET_KEY=$ARCJET_KEY npm run postinstall && npm run build | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: file is missing a trailing newline (the diff shows |
||
|
|
||
| CMD ["npm", "run", "start"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stated goal of this PR is to stop silently disabling enforcement when
ARCJET_KEYis unset, butprocess.env.ARCJET_KEY!only silences the TypeScript check — at runtimeundefinedis still passed toarcjetNextjs, so behavior depends on how the SDK handles it. Consider matching the explicit-throw pattern used inexamples/eve-agent/agent/arcjet.tsandexamples/firebase-functions/src/index.tsso misconfiguration fails loudly here too.