Skip to content

Commit 95b9ca4

Browse files
authored
feat(registration): allow self-hosted users to disable registration altogether (#2365)
* feat(registration): allow self-hosted users to disable registration altogether * updated tests * fix build
1 parent 746ff68 commit 95b9ca4

File tree

66 files changed

+332
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+332
-154
lines changed

apps/sim/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ DATABASE_URL="postgresql://postgres:password@localhost:5432/postgres"
44
# PostgreSQL Port (Optional) - defaults to 5432 if not specified
55
# POSTGRES_PORT=5432
66

7-
# Authentication (Required)
7+
# Authentication (Required unless DISABLE_AUTH=true)
88
BETTER_AUTH_SECRET=your_secret_key # Use `openssl rand -hex 32` to generate, or visit https://www.better-auth.com/docs/installation
99
BETTER_AUTH_URL=http://localhost:3000
1010

11+
# Authentication Bypass (Optional - for self-hosted deployments behind private networks)
12+
# DISABLE_AUTH=true # Uncomment to bypass authentication entirely. Creates an anonymous session for all requests.
13+
1114
# NextJS (Required)
1215
NEXT_PUBLIC_APP_URL=http://localhost:3000
1316

apps/sim/app/(auth)/components/oauth-provider-checker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use server'
22

33
import { env } from '@/lib/core/config/env'
4-
import { isProd } from '@/lib/core/config/environment'
4+
import { isProd } from '@/lib/core/config/feature-flags'
55

66
export async function getOAuthProviderStatus() {
77
const githubAvailable = !!(env.GITHUB_CLIENT_ID && env.GITHUB_CLIENT_SECRET)

apps/sim/app/(auth)/login/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getOAuthProviderStatus } from '@/app/(auth)/components/oauth-provider-checker'
22
import LoginForm from '@/app/(auth)/login/login-form'
33

4-
// Force dynamic rendering to avoid prerender errors with search params
54
export const dynamic = 'force-dynamic'
65

76
export default async function LoginPage() {

apps/sim/app/(auth)/signup/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { env, isTruthy } from '@/lib/core/config/env'
1+
import { isRegistrationDisabled } from '@/lib/core/config/feature-flags'
22
import { getOAuthProviderStatus } from '@/app/(auth)/components/oauth-provider-checker'
33
import SignupForm from '@/app/(auth)/signup/signup-form'
44

55
export const dynamic = 'force-dynamic'
66

77
export default async function SignupPage() {
8-
const { githubAvailable, googleAvailable, isProduction } = await getOAuthProviderStatus()
9-
10-
if (isTruthy(env.DISABLE_REGISTRATION)) {
8+
if (isRegistrationDisabled) {
119
return <div>Registration is disabled, please contact your admin.</div>
1210
}
1311

12+
const { githubAvailable, googleAvailable, isProduction } = await getOAuthProviderStatus()
13+
1414
return (
1515
<SignupForm
1616
githubAvailable={githubAvailable}

apps/sim/app/(auth)/verify/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isEmailVerificationEnabled, isProd } from '@/lib/core/config/environment'
1+
import { isEmailVerificationEnabled, isProd } from '@/lib/core/config/feature-flags'
22
import { hasEmailService } from '@/lib/messaging/email/mailer'
33
import { VerifyContent } from '@/app/(auth)/verify/verify-content'
44

apps/sim/app/(landing)/careers/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
SelectValue,
1414
} from '@/components/ui/select'
1515
import { Textarea } from '@/components/ui/textarea'
16-
import { isHosted } from '@/lib/core/config/environment'
16+
import { isHosted } from '@/lib/core/config/feature-flags'
1717
import { cn } from '@/lib/core/utils/cn'
1818
import { createLogger } from '@/lib/logs/console/logger'
1919
import { quickValidateEmail } from '@/lib/messaging/email/validation'

apps/sim/app/(landing)/components/legal-layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { isHosted } from '@/lib/core/config/environment'
3+
import { isHosted } from '@/lib/core/config/feature-flags'
44
import { soehne } from '@/app/_styles/fonts/soehne/soehne'
55
import Footer from '@/app/(landing)/components/footer/footer'
66
import Nav from '@/app/(landing)/components/nav/nav'

apps/sim/app/(landing)/components/nav/nav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Link from 'next/link'
77
import { useRouter } from 'next/navigation'
88
import { GithubIcon } from '@/components/icons'
99
import { useBrandConfig } from '@/lib/branding/branding'
10-
import { isHosted } from '@/lib/core/config/environment'
10+
import { isHosted } from '@/lib/core/config/feature-flags'
1111
import { createLogger } from '@/lib/logs/console/logger'
1212
import { soehne } from '@/app/_styles/fonts/soehne/soehne'
1313
import { getFormattedGitHubStars } from '@/app/(landing)/actions/github'
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
import { toNextJsHandler } from 'better-auth/next-js'
2+
import { type NextRequest, NextResponse } from 'next/server'
23
import { auth } from '@/lib/auth'
4+
import { createAnonymousSession, ensureAnonymousUserExists } from '@/lib/auth/anonymous'
5+
import { isAuthDisabled } from '@/lib/core/config/feature-flags'
36

47
export const dynamic = 'force-dynamic'
58

6-
export const { GET, POST } = toNextJsHandler(auth.handler)
9+
const { GET: betterAuthGET, POST: betterAuthPOST } = toNextJsHandler(auth.handler)
10+
11+
export async function GET(request: NextRequest) {
12+
const url = new URL(request.url)
13+
const path = url.pathname.replace('/api/auth/', '')
14+
15+
if (path === 'get-session' && isAuthDisabled) {
16+
await ensureAnonymousUserExists()
17+
return NextResponse.json(createAnonymousSession())
18+
}
19+
20+
return betterAuthGET(request)
21+
}
22+
23+
export const POST = betterAuthPOST

apps/sim/app/api/auth/socket-token/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { headers } from 'next/headers'
22
import { NextResponse } from 'next/server'
33
import { auth } from '@/lib/auth'
4+
import { isAuthDisabled } from '@/lib/core/config/feature-flags'
45

56
export async function POST() {
67
try {
8+
if (isAuthDisabled) {
9+
return NextResponse.json({ token: 'anonymous-socket-token' })
10+
}
11+
712
const hdrs = await headers()
813
const response = await auth.api.generateOneTimeToken({
914
headers: hdrs,

0 commit comments

Comments
 (0)