🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Fix disable signup (#260)
Bill Yangabe819c4114e
diff --git a/client/src/app/login/page.tsx b/client/src/app/login/page.tsxindex 462c4465c..c08a662a0 100644--- a/client/src/app/login/page.tsx+++ b/client/src/app/login/page.tsx@@ -13,10 +13,12 @@ import { useState } from "react";import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";import { useSetPageTitle } from "../../hooks/useSetPageTitle";import { authClient } from "../../lib/auth";-import { DISABLE_SIGNUP, IS_CLOUD } from "../../lib/const";+import { IS_CLOUD } from "../../lib/const";import { userStore } from "../../lib/userStore";+import { useConfigs } from "../../lib/configs";export default function Page() {+ const { configs, isLoading: isLoadingConfigs } = useConfigs();useSetPageTitle("Rybbit · Login");const [email, setEmail] = useState("");const [password, setPassword] = useState("");@@ -150,8 +152,8 @@ export default function Page() {<AlertDescription>{error}</AlertDescription></Alert>)}-- {!DISABLE_SIGNUP && (++ {(!configs?.disableSignup || !isLoadingConfigs) && (<div className="text-center text-sm">Don't have an account?{" "}<Link href="/signup" className="underline">diff --git a/client/src/app/signup/page.tsx b/client/src/app/signup/page.tsxindex f9611c02e..d579e229b 100644--- a/client/src/app/signup/page.tsx+++ b/client/src/app/signup/page.tsx@@ -27,7 +27,8 @@ import { Logo } from "../../components/Logo";import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";import { useSetPageTitle } from "../../hooks/useSetPageTitle";import { authClient } from "../../lib/auth";-import { DISABLE_SIGNUP, IS_CLOUD } from "../../lib/const";+import { useConfigs } from "../../lib/configs";+import { IS_CLOUD } from "../../lib/const";import { userStore } from "../../lib/userStore";import { cn } from "../../lib/utils";@@ -52,6 +53,7 @@ function StepHandler({ onSetStep }: { onSetStep: (step: number) => void }) {}export default function SignupPage() {+ const { configs, isLoading: isLoadingConfigs } = useConfigs();useSetPageTitle("Rybbit · Signup");const [currentStep, setCurrentStep] = useState(1);@@ -494,7 +496,11 @@ export default function SignupPage() {// Calculate progress percentageconst progressPercentage = ((currentStep - 1) / 3) * 100;- if(DISABLE_SIGNUP) {+ if (isLoadingConfigs) {+ return null;+ }++ if (configs?.disableSignup) {return (<div className="flex justify-center items-center h-screen w-full"><Card className="w-full max-w-sm p-1">@@ -506,14 +512,19 @@ export default function SignupPage() {</CardHeader><CardContent><div className="flex flex-col gap-6">- <p className="text-center">New account registration is currently disabled. If you have an account, you can- {" "}<Link href="/login" className="underline">sign in</Link>.+ <p className="text-center">+ New account registration is currently disabled. If you have an+ account, you can{" "}+ <Link href="/login" className="underline">+ sign in+ </Link>+ .</p></div></CardContent></Card></div>- )+ );}return (@@ -548,10 +559,24 @@ export default function SignupPage() {{[1, 2, 3, 4].map((step) => (<divkey={step}- className={cn("flex items-center space-x-3 py-3", currentStep === step ? "text-emerald-400 font-medium" : currentStep > step ? "text-muted-foreground" : "text-muted-foreground/60")}+ className={cn(+ "flex items-center space-x-3 py-3",+ currentStep === step+ ? "text-emerald-400 font-medium"+ : currentStep > step+ ? "text-muted-foreground"+ : "text-muted-foreground/60"+ )}><div- className={cn("flex items-center justify-center w-8 h-8 rounded-full transition-all duration-300", currentStep === step ? "bg-emerald-600 text-primary-foreground" : currentStep > step ? "bg-emerald-600/20 text-emerald-400" : "bg-muted-foreground/20 text-muted-foreground")}+ className={cn(+ "flex items-center justify-center w-8 h-8 rounded-full transition-all duration-300",+ currentStep === step+ ? "bg-emerald-600 text-primary-foreground"+ : currentStep > step+ ? "bg-emerald-600/20 text-emerald-400"+ : "bg-muted-foreground/20 text-muted-foreground"+ )}>{currentStep > step ? (<Check className="h-4 w-4" />diff --git a/client/src/lib/configs.ts b/client/src/lib/configs.tsnew file mode 100644index 000000000..413437a3f--- /dev/null+++ b/client/src/lib/configs.ts@@ -0,0 +1,20 @@+import { useQuery } from "@tanstack/react-query";+import { authedFetchWithError } from "../api/utils";+import { BACKEND_URL } from "./const";++interface Configs {+ disableSignup: boolean;+}++export function useConfigs() {+ const { data, isLoading, error } = useQuery<Configs>({+ queryKey: ["configs"],+ queryFn: () => authedFetchWithError<Configs>(`${BACKEND_URL}/config`),+ });++ return {+ configs: data,+ isLoading,+ error,+ };+}diff --git a/client/src/lib/const.ts b/client/src/lib/const.tsindex cccee0b4f..fa28ab75f 100644--- a/client/src/lib/const.ts+++ b/client/src/lib/const.ts@@ -2,6 +2,5 @@ export const BACKEND_URL =process.env.NEXT_PUBLIC_BACKEND_URL === "http://localhost:3001"? "http://localhost:3001": `${process.env.NEXT_PUBLIC_BACKEND_URL}/api`;-export const DISABLE_SIGNUP = process.env.NEXT_PUBLIC_DISABLE_SIGNUP === "true";export const IS_CLOUD = process.env.NEXT_PUBLIC_CLOUD === "true";export const IS_DEMO = process.env.NEXT_PUBLIC_DEMO === "true";diff --git a/restart.sh b/restart.shindex 5df7be3e3..e1c78f49f 100644--- a/restart.sh+++ b/restart.sh@@ -6,7 +6,7 @@ set -eecho "Restarting services..."# Stop all services-docker compose stop+docker compose down# Check if .env file existsif [ ! -f .env ]; then@@ -18,13 +18,13 @@ fi# Load environment variablessource .env-# Start the appropriate services+# Start the appropriate services with updated environment variablesif [ "$USE_WEBSERVER" = "false" ]; then# Start without the caddy service when using --no-webserver- docker compose start backend client clickhouse postgres+ docker compose up -d backend client clickhouse postgreselse# Start all services including caddy- docker compose start+ docker compose up -dfiecho "Services restarted. You can monitor logs with: docker compose logs -f"\ No newline at end of filediff --git a/server/src/api/getConfig.ts b/server/src/api/getConfig.tsnew file mode 100644index 000000000..0d0c2193d--- /dev/null+++ b/server/src/api/getConfig.ts@@ -0,0 +1,8 @@+import { FastifyRequest, FastifyReply } from "fastify";+import { DISABLE_SIGNUP } from "../lib/const.js";++export async function getConfig(request: FastifyRequest, reply: FastifyReply) {+ return reply.send({+ disableSignup: DISABLE_SIGNUP,+ });+}diff --git a/server/src/index.ts b/server/src/index.tsindex c0e9e77dc..f3021cd00 100644--- a/server/src/index.ts+++ b/server/src/index.ts@@ -58,6 +58,7 @@ import { getSubscription } from "./api/stripe/getSubscription.js";import { handleWebhook } from "./api/stripe/webhook.js";import { IS_CLOUD } from "./lib/const.js";import { addUserToOrganization } from "./api/user/addUserToOrganization.js";+import { getConfig } from "./api/getConfig.js";const __filename = fileURLToPath(import.meta.url);const __dirname = dirname(__filename);@@ -120,6 +121,7 @@ const PUBLIC_ROUTES: string[] = ["/track","/script","/auth",+ "/config","/api/auth","/api/auth/callback/google","/api/auth/callback/github",@@ -229,6 +231,7 @@ server.get("/events/names/:site", getEventNames);server.get("/events/properties/:site", getEventProperties);// Administrative+server.get("/config", getConfig);server.post("/add-site", addSite);server.post("/change-site-domain", changeSiteDomain);server.post("/change-site-public", changeSitePublic);diff --git a/setup.sh b/setup.shindex 5f749fd95..81ed50736 100644--- a/setup.sh+++ b/setup.sh@@ -108,10 +108,10 @@ cat > .env << EOLDOMAIN_NAME=${DOMAIN_NAME}BASE_URL=${BASE_URL}BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}-DISABLE_SIGNUP=falseUSE_WEBSERVER=${USE_WEBSERVER}HOST_BACKEND_PORT=${HOST_BACKEND_PORT}HOST_CLIENT_PORT=${HOST_CLIENT_PORT}+DISABLE_SIGNUP=falseEOLecho ".env file created successfully with domain ${DOMAIN_NAME}."