Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@vercel/otel": "^1.13.0",
"@vercel/speed-insights": "^1.2.0",
"ansis": "^3.17.0",
"botid": "^1.5.8",
"cheerio": "^1.0.0",
"chrono-node": "^2.8.4",
"class-variance-authority": "^0.7.1",
Expand Down Expand Up @@ -1316,6 +1317,8 @@

"boolbase": ["[email protected]", "", {}, "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww=="],

"botid": ["[email protected]", "", { "peerDependencies": { "next": "*", "react": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["next", "react"] }, "sha512-1A/TvyoLtYLlncd30Uyp6ErAEHj4lSpOKqYTJSxX+aSaFUyYSX6rZuYDSX7Zp1kRnoraWHa/4K72mHcjRsUIlQ=="],

"brace-expansion": ["[email protected]", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg=="],

"braces": ["[email protected]", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="],
Expand Down
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { withBotId } from 'botid/next/config';

/** @type {import('next').NextConfig} */
const config = {
eslint: {
Expand Down Expand Up @@ -82,4 +84,6 @@ const config = {
skipTrailingSlashRedirect: true,
}

export default config
const exportedConfig = process.env.NEXT_PUBLIC_USE_BOT_ID === '1' ? withBotId(config) : config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Bot Detection Inconsistency Across Build and Runtime

The NEXT_PUBLIC_USE_BOT_ID environment variable controls bot detection, but it's evaluated at build time in next.config.mjs for the withBotId wrapper and at runtime in src/configs/flags.ts. This difference can cause inconsistent bot detection behavior if the variable's value isn't consistent between build and runtime.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am aware of this inconsistency, this HOF only configures certain rewrites to make it more effective in production


export default exportedConfig
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@vercel/otel": "^1.13.0",
"@vercel/speed-insights": "^1.2.0",
"ansis": "^3.17.0",
"botid": "^1.5.8",
"cheerio": "^1.0.0",
"chrono-node": "^2.8.4",
"class-variance-authority": "^0.7.1",
Expand Down
9 changes: 9 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ import { GTMHead } from '@/features/google-tag-manager'
import { Toaster } from '@/ui/primitives/toaster'
import { Analytics } from '@vercel/analytics/next'
import { SpeedInsights } from '@vercel/speed-insights/next'
import { BotIdClient } from 'botid/client'
import Head from 'next/head'
import { Metadata } from 'next/types'
import { Suspense } from 'react'
import { Body } from './layout.client'

const protectedRoutes = [
{
path: '/sign-up',
method: 'POST',
},
]

export const metadata: Metadata = {
metadataBase: new URL(BASE_URL),
title: {
Expand Down Expand Up @@ -42,6 +50,7 @@ export default function RootLayout({
<html lang="en" suppressHydrationWarning>
<Head>
<GTMHead />
<BotIdClient protect={protectedRoutes} />
</Head>
<Body>
<ClientProviders>
Expand Down
1 change: 1 addition & 0 deletions src/configs/flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const ALLOW_SEO_INDEXING = process.env.ALLOW_SEO_INDEXING === '1'
export const USE_BOT_ID = process.env.NEXT_PUBLIC_USE_BOT_ID === '1'
export const VERBOSE = process.env.NEXT_PUBLIC_VERBOSE === '1'
export const INCLUDE_BILLING = process.env.NEXT_PUBLIC_INCLUDE_BILLING === '1'
export const USE_MOCK_DATA =
Expand Down
42 changes: 40 additions & 2 deletions src/server/auth/auth-actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use server'

import { USE_BOT_ID } from '@/configs/flags'
import { AUTH_URLS, PROTECTED_URLS } from '@/configs/urls'
import { USER_MESSAGES } from '@/configs/user-messages'
import { actionClient } from '@/lib/clients/action'
Expand All @@ -12,17 +13,19 @@ import {
shouldWarnAboutAlternateEmail,
validateEmail,
} from '@/server/auth/validate-email'
import { Provider } from '@supabase/supabase-js'
import { checkBotId } from 'botid/server'
import { returnValidationErrors } from 'next-safe-action'
import { headers } from 'next/headers'
import { redirect } from 'next/navigation'
import { z } from 'zod'
import { forgotPasswordSchema, signInSchema, signUpSchema } from './auth.types'

const ProviderSchema = z.enum(['google', 'github'])

export const signInWithOAuthAction = actionClient
.schema(
z.object({
provider: z.string() as unknown as z.ZodType<Provider>,
provider: ProviderSchema,
returnTo: relativeUrlSchema.optional(),
})
)
Expand Down Expand Up @@ -89,6 +92,40 @@ export const signUpAction = actionClient
})
}

// bot detection
if (USE_BOT_ID) {
const verification = await checkBotId()

if (verification.isBot) {
l.warn(
{
key: 'sign_up_action:bot_detection_triggered',
context: {
email,
verification,
},
},
`Bot detection prevented sign up for: ${email}`
)

return returnServerError(
'Access denied. Please contact support if this issue persists.'
)
} else {
l.info(
{
key: 'sign_up_action:bot_detection_passed',
context: {
email,
verification,
},
},
`Bot detection passed sign up for: ${email}`
)
}
}

// email validation
const validationResult = await validateEmail(email)

if (validationResult?.data) {
Expand All @@ -103,6 +140,7 @@ export const signUpAction = actionClient
}
}

// sign up
const { error } = await supabase.auth.signUp({
email,
password,
Expand Down
Loading