diff --git a/web/normogen-web/src/pages/RegisterPage.tsx b/web/normogen-web/src/pages/RegisterPage.tsx index 5da1fc5..fcd8d7b 100644 --- a/web/normogen-web/src/pages/RegisterPage.tsx +++ b/web/normogen-web/src/pages/RegisterPage.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import { useState, type FC } from 'react'; import { useNavigate, Link } from 'react-router-dom'; import { Container, @@ -12,14 +12,15 @@ import { } from '@mui/material'; import { useAuthStore } from '../store/useStore'; -export const RegisterPage: React.FC = () => { +export const RegisterPage: FC = () => { const navigate = useNavigate(); + const { register, isLoading, error, clearError } = useAuthStore(); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); + const [recoveryPhrase, setRecoveryPhrase] = useState(''); const [passwordError, setPasswordError] = useState(''); - const { register, isLoading, error, clearError } = useAuthStore(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -30,54 +31,32 @@ export const RegisterPage: React.FC = () => { setPasswordError('Passwords do not match'); return; } - - if (password.length < 6) { - setPasswordError('Password must be at least 6 characters'); + if (password.length < 8) { + setPasswordError('Password must be at least 8 characters'); return; } - + try { - await register(username, email, password); + // Pass the recovery phrase (optional) to the store; the store derives + // the wrapped-DEK forms from it. + await register(username, email, password, recoveryPhrase || undefined); navigate('/'); - } catch (err) { - // Error is handled by the store + } catch { + /* error surfaced via store */ } }; return ( - - + + Create Account - - Join Normogen Healthcare Platform - - {error && ( + {(error || passwordError) && ( - {error} - - )} - - {passwordError && ( - - {passwordError} + {error || passwordError} )} @@ -86,23 +65,18 @@ export const RegisterPage: React.FC = () => { margin="normal" required fullWidth - id="username" label="Username" - name="username" - autoComplete="username" - autoFocus value={username} onChange={(e) => setUsername(e.target.value)} disabled={isLoading} + autoFocus /> setEmail(e.target.value)} disabled={isLoading} @@ -111,11 +85,8 @@ export const RegisterPage: React.FC = () => { margin="normal" required fullWidth - name="password" label="Password" type="password" - id="password" - autoComplete="new-password" value={password} onChange={(e) => setPassword(e.target.value)} disabled={isLoading} @@ -124,14 +95,21 @@ export const RegisterPage: React.FC = () => { margin="normal" required fullWidth - name="confirmPassword" label="Confirm Password" type="password" - id="confirmPassword" value={confirmPassword} onChange={(e) => setConfirmPassword(e.target.value)} disabled={isLoading} /> + setRecoveryPhrase(e.target.value)} + disabled={isLoading} + helperText="If you forget your password, this phrase is your only way to recover your encrypted data. Save it somewhere safe." + />