diff --git a/crux-frontend/app/index.tsx b/crux-frontend/app/index.tsx index 1e76c53..f9de227 100644 --- a/crux-frontend/app/index.tsx +++ b/crux-frontend/app/index.tsx @@ -8,17 +8,25 @@ export default function Login() { const router = useRouter(); const {signin, loading, error} = useAuth(); const [identifier, setIdentifier] = useState(''); + const [verificationCode, setVerificationCode] = useState(''); + const [isVerificationStep, setIsVerificationStep] = useState(false); const handleSignin = async () => { const success = await signin(identifier); if (success) { - router.push({ - pathname: '/verify/[phone]', - params: {phone: identifier}, - }); + setIsVerificationStep(true); } }; + const handleVerification = async () => { + // Add logic to verify the code + // If successful, navigate to the next screen + router.push({ + pathname: '/verify/[phone]', + params: {phone: identifier}, + }); + }; + return ( @@ -28,43 +36,68 @@ export default function Login() { - - + {isVerificationStep ? ( + <> + Verify your email + + We've sent a verification code to your email. Please enter it below. + + + + Verify + + + ) : ( + <> + + - {error && {error}} + {error && {error}} - - Sign in - + + Sign in + - - - Sign up - - + + + Sign up + + - - - - - - - - - - - - + + + + + + + + + + + + + + )} ); } diff --git a/crux-frontend/app/signup.tsx b/crux-frontend/app/signup.tsx index 29fe25d..bce9ba0 100644 --- a/crux-frontend/app/signup.tsx +++ b/crux-frontend/app/signup.tsx @@ -11,6 +11,8 @@ export default function SignUp() { const [lastName, setLastName] = useState(''); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); + const [verificationCode, setVerificationCode] = useState(''); + const [isVerificationStep, setIsVerificationStep] = useState(false); const handleSignup = async () => { const success = await signup({ @@ -20,77 +22,112 @@ export default function SignUp() { phone, }); if (success) { - router.push({pathname: '/verify/[phone]', params: {phone}}); + setIsVerificationStep(true); } }; + const handleVerification = async () => { + // Add logic to verify the code + // If successful, navigate to the next screen + router.push({pathname: '/verify/[phone]', params: {phone}}); + }; + return ( router.canGoBack() && router.back()}> - 1/3 + {isVerificationStep ? '2/3' : '1/3'} - Let's get to know you! - - Your journey starts here — just a few quick details. - - - - Your name - - + {isVerificationStep ? ( + <> + Verify your email + + We've sent a verification code to your email. Please enter it below. + - + + + + + ) : ( + <> + Let's get to know you! + + Your journey starts here — just a few quick details. + - Email - + + Your name + + + + - Phone number - + Email + - {error && {error}} + Phone number + - - - - + {error && {error}} + + + + + + + )} ); } diff --git a/crux-frontend/hooks/useAuth.ts b/crux-frontend/hooks/useAuth.ts index 064d768..59ed41f 100644 --- a/crux-frontend/hooks/useAuth.ts +++ b/crux-frontend/hooks/useAuth.ts @@ -44,7 +44,21 @@ const useAuth = () => { resolve(false); return; } - resolve(true); + // Handle email verification + if (result?.userConfirmed === false) { + // Send verification code to user's email + result.user.getAttributeVerificationCode('email', { + onSuccess: () => { + resolve(true); + }, + onFailure: (err) => { + setError(err.message || 'Failed to send verification code'); + resolve(false); + }, + }); + } else { + resolve(true); + } } ); }); @@ -66,9 +80,25 @@ const useAuth = () => { return new Promise((resolve) => { cognitoUser.authenticateUser(authenticationDetails, { - onSuccess: () => { + onSuccess: (session) => { setLoading(false); - resolve(true); + // Check if email is verified + cognitoUser.getUserAttributes((err, attributes) => { + if (err) { + setError(err.message || 'Failed to get user attributes'); + resolve(false); + return; + } + const emailVerified = attributes?.find( + (attr) => attr.getName() === 'email_verified' + )?.getValue(); + if (emailVerified === 'true') { + resolve(true); + } else { + setError('Email not verified'); + resolve(false); + } + }); }, onFailure: (err) => { setLoading(false); diff --git a/crux-frontend/package-lock.json b/crux-frontend/package-lock.json index c2dcac6..e7033d7 100644 --- a/crux-frontend/package-lock.json +++ b/crux-frontend/package-lock.json @@ -7010,10 +7010,11 @@ } }, "node_modules/@types/jest": { - "version": "29.5.13", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", - "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", + "version": "29.5.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.14.tgz", + "integrity": "sha512-ZN+4sdnLUbo8EVvVc2ao0GFW6oVrQRPn4K2lglySj7APvSrgzxHiNNK99us4WDMi57xxA2yggblIAMNhXOotLQ==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" diff --git a/infra/main.tf b/infra/main.tf index a5ac030..7b948f8 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -420,4 +420,4 @@ resource "aws_security_group" "alb_sg" { protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } -} \ No newline at end of file +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..5db72dd --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended" + ] +}