diff --git a/maternal-app/maternal-app-backend/src/modules/auth/auth.controller.ts b/maternal-app/maternal-app-backend/src/modules/auth/auth.controller.ts index cb708a7..6963856 100644 --- a/maternal-app/maternal-app-backend/src/modules/auth/auth.controller.ts +++ b/maternal-app/maternal-app-backend/src/modules/auth/auth.controller.ts @@ -14,6 +14,7 @@ import { Param, Req, } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { AuthService } from './auth.service'; import { PasswordResetService } from './password-reset.service'; import { MFAService } from './mfa.service'; @@ -44,8 +45,25 @@ export class AuthController { private readonly sessionService: SessionService, private readonly deviceTrustService: DeviceTrustService, private readonly biometricAuthService: BiometricAuthService, + private readonly configService: ConfigService, ) {} + @Public() + @Get('registration/config') + @HttpCode(HttpStatus.OK) + async getRegistrationConfig() { + const registrationMode = this.configService.get('REGISTRATION_MODE', 'invite_only'); + const requireInviteCode = registrationMode === 'invite_only'; + + return { + success: true, + data: { + registrationMode, + requireInviteCode, + }, + }; + } + @Public() @Post('register') @HttpCode(HttpStatus.CREATED) diff --git a/maternal-web/app/(auth)/register/page.tsx b/maternal-web/app/(auth)/register/page.tsx index 8c445d5..141b061 100644 --- a/maternal-web/app/(auth)/register/page.tsx +++ b/maternal-web/app/(auth)/register/page.tsx @@ -23,6 +23,7 @@ import * as z from 'zod'; import { useAuth } from '@/lib/auth/AuthContext'; import Link from 'next/link'; import { useTheme } from '@mui/material/styles'; +import apiClient from '@/lib/api/client'; const registerSchema = z.object({ name: z.string().min(2, 'Name must be at least 2 characters'), @@ -79,6 +80,8 @@ export default function RegisterPage() { const [isLoading, setIsLoading] = useState(false); const [userAge, setUserAge] = useState(null); const [requiresParentalConsent, setRequiresParentalConsent] = useState(false); + const [requireInviteCode, setRequireInviteCode] = useState(false); + const [loadingConfig, setLoadingConfig] = useState(true); const { register: registerUser } = useAuth(); const { @@ -95,6 +98,26 @@ export default function RegisterPage() { }, }); + // Fetch registration configuration on mount + useEffect(() => { + const fetchRegistrationConfig = async () => { + try { + const response = await apiClient.get('/api/v1/auth/registration/config'); + if (response.data?.success && response.data?.data) { + setRequireInviteCode(response.data.data.requireInviteCode); + } + } catch (error) { + console.error('Failed to fetch registration config:', error); + // Default to not requiring invite code if fetch fails + setRequireInviteCode(false); + } finally { + setLoadingConfig(false); + } + }; + + fetchRegistrationConfig(); + }, []); + // Watch date of birth to calculate age and show parental consent if needed const dateOfBirth = watch('dateOfBirth'); @@ -244,26 +267,30 @@ export default function RegisterPage() { }} /> - + {requireInviteCode && ( + + )}