mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-24 23:41:10 +02:00
Implemented comprehensive registration control system that allows administrators to disable new user registrations through the admin panel. This provides better control over user access and supports closed registration scenarios. Backend changes: - Added disable_registration field to SiteConfiguration model (db.py) - Created migration #39 to add disable_registration column with default false - Updated SiteConfigurationBase, Update, and Read schemas - Enhanced registration_allowed() dependency to check database toggle - Returns 403 with clear message when registration is disabled Frontend changes: - Added disable_registration to SiteConfig interface and default config - Updated LocalLoginForm to conditionally hide "Sign up" link when disabled - Added RouteGuard support for "registration" route key - Protected /register page with RouteGuard (shows 404 when disabled) - Added "Registration Control" section to admin site-settings page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useSiteConfig } from "@/contexts/SiteConfigContext";
|
|
|
|
interface RouteGuardProps {
|
|
children: React.ReactNode;
|
|
routeKey: "pricing" | "docs" | "contact" | "terms" | "privacy" | "registration";
|
|
}
|
|
|
|
export function RouteGuard({ children, routeKey }: RouteGuardProps) {
|
|
const { config, isLoading } = useSiteConfig();
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (isLoading) return;
|
|
|
|
// Special case: registration uses disable_registration instead of disable_registration_route
|
|
const disableKey = routeKey === "registration"
|
|
? "disable_registration"
|
|
: (`disable_${routeKey}_route` as keyof typeof config);
|
|
const isDisabled = config[disableKey as keyof typeof config];
|
|
|
|
if (isDisabled) {
|
|
router.replace("/404");
|
|
}
|
|
}, [config, isLoading, routeKey, router]);
|
|
|
|
// Show loading state while checking configuration
|
|
if (isLoading) {
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-white dark:bg-black">
|
|
<div className="text-neutral-600 dark:text-neutral-400">Loading...</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Check if route is disabled
|
|
// Special case: registration uses disable_registration instead of disable_registration_route
|
|
const disableKey = routeKey === "registration"
|
|
? "disable_registration"
|
|
: (`disable_${routeKey}_route` as keyof typeof config);
|
|
const isDisabled = config[disableKey as keyof typeof config];
|
|
|
|
if (isDisabled) {
|
|
return null;
|
|
}
|
|
|
|
return <>{children}</>;
|
|
}
|