Repository: tamadekk/learn-app
Pull request #9: 5 implement login authentication
Author: login: tamadekk
Created: 2025-05-02T12:54:37Z | Merged: 2025-05-02T16:53:46Z



<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced authentication context and provider, enabling app-wide access to authentication state and actions.
  - Added login form with client-side validation, CAPTCHA verification, and Firebase authentication integration.
  - Implemented registration form with schema-based validation and user creation in Firebase.
  - Added middleware to enforce authentication on protected routes, redirecting unauthenticated users to login.
- **Improvements**
  - Enhanced form components to support flexible, type-safe form value structures.
  - Centralized and strengthened input validation using zod schemas for both login and registration.
  - Added constants for authentication token management and cookie handling.
  - Updated Firebase client initialization to use environment variables and support authentication exports.
  - Wrapped app layout with authentication provider for consistent auth state access.
- **Dependencies**
  - Added `@hookform/resolvers`, `nookies`, and `zod` to project dependencies.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/bun.lockb b/bun.lockb
index 9718c2f..7e23fa1 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/firebase/clientApp.ts b/firebase/clientApp.ts
index a32d308..6c9b4a1 100644
--- a/firebase/clientApp.ts
+++ b/firebase/clientApp.ts
@@ -1,18 +1,17 @@
 import { initializeApp } from 'firebase/app';
+import { getAuth } from 'firebase/auth';
 import { getFirestore } from 'firebase/firestore';
 
 const firebaseConfig = {
-	apiKey: process.env.FIREBASE_API_KEY,
-	authDomain: process.env.FIREBASE_AUTH_DOMAIN,
-	projectId: process.env.FIREBASE_PROJECT_ID,
-	storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
-	messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
-	appId: process.env.FIREBASE_APP_ID,
-	measurementId: process.env.FIREBASE_MEASUREMENT_ID,
+	apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
+	authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
+	projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
+	storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
+	messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
+	appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
+	measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
 };
 
-const app = initializeApp(firebaseConfig);
-
-export default app;
-
+export const app = initializeApp(firebaseConfig);
+export const auth = getAuth(app);
 export const db = getFirestore(app);
diff --git a/package.json b/package.json
index 8b24485..48ea0f3 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
 		]
 	},
 	"dependencies": {
+		"@hookform/resolvers": "^4.1.2",
 		"class-variance-authority": "^0.7.1",
 		"eslint": "^9.17.0",
 		"eslint-config-prettier": "^9.1.0",
@@ -24,6 +25,7 @@
 		"firebase": "^11.3.1",
 		"husky": "^9.1.7",
 		"next": "15.1.0",
+		"nookies": "^2.5.2",
 		"prettier": "^3.4.2",
 		"react": "^19.0.0",
 		"react-dom": "^19.0.0",
@@ -31,7 +33,8 @@
 		"react-google-recaptcha": "^3.1.0",
 		"react-hook-form": "^7.54.1",
 		"sharp": "^0.33.5",
-		"tailwind-merge": "^2.5.5"
+		"tailwind-merge": "^2.5.5",
+		"zod": "^3.24.2"
 	},
 	"devDependencies": {
 		"@eslint/js": "^9.17.0",
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 42f7ec5..66a1097 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -4,6 +4,7 @@ import './globals.css';
 
 import Header from '@/components/Header/Header';
 import Footer from '@/components/Footer/Footer';
+import { AuthProvider } from '@/context/AuthContext';
 const geistSans = Geist({
 	variable: '--font-geist-sans',
 	subsets: ['latin'],
@@ -28,10 +29,11 @@ export default function RootLayout({
 			<body
 				className={`${geistSans.variable} ${geistMono.variable} antialiased`}
 			>
-				<Header />
-
-				{children}
-				<Footer />
+				<AuthProvider>
+					<Header />
+					{children}
+					<Footer />
+				</AuthProvider>
 			</body>
 		</html>
 	);
diff --git a/src/app/login/LoginForm.tsx b/src/app/login/LoginForm.tsx
new file mode 100644
index 0000000..4f3a981
--- /dev/null
+++ b/src/app/login/LoginForm.tsx
@@ -0,0 +1,144 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { SubmitHandler, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import Image from 'next/image';
+import ReCAPTCHA from 'react-google-recaptcha';
+import Input from '@/shared/Input/Input';
+import Button from '@/shared/Button/Button';
+
+import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { LoginFormValues } from '@/shared/Input/types';
+import { loginSchema } from './validation';
+import { userLogin, LoginResult } from './utils';
+import Link from 'next/link';
+
+const Login = () => {
+	const [captchaCompleted, setCaptchaCompleted] = useState(false);
+	const [captchaWarning, setCaptchaWarning] = useState(false);
+	const [isPasswordVisible, setPasswordVisible] = useState(false);
+	const [loginError, setLoginError] = useState<string | null>(null);
+
+	const router = useRouter();
+	const searchParams = useSearchParams();
+	const {
+		register,
+		formState: { errors, isSubmitting },
+		handleSubmit,
+	} = useForm<LoginFormValues>({ resolver: zodResolver(loginSchema) });
+
+	const onSubmit: SubmitHandler<LoginFormValues> = async (data) => {
+		if (!captchaCompleted) {
+			setCaptchaWarning(true);
+			return;
+		}
+		if (!data) return;
+
+		setLoginError(null);
+		const res = (await userLogin(data)) as LoginResult;
+
+		if (res.success) {
+			const returnUrl = searchParams.get('returnUrl') || '/';
+			router.push(returnUrl);
+		} else if (res.error) {
+			setLoginError(res.error);
+		}
+	};
+
+	const handleToggle = () => {
+		setPasswordVisible(!isPasswordVisible);
+	};
+
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(value ? true : false);
+	};
+
+	return (
+		<div className='min-h-screen flex items-center justify-center pb-32'>
+			<div className='flex flex-col items-center gap-5'>
+				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
+					Sign in
+				</p>
+				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
+				{(errors.email || errors.password) && (
+					<p className='text-red-600 font-poppins font-semibold inline-block'>
+						Please enter a valid email and password
+					</p>
+				)}
+				<form
+					className='flex flex-col items-center gap-4'
+					onSubmit={handleSubmit(onSubmit)}
+				>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>Email</label>
+						<Input<LoginFormValues>
+							icon={userIcon}
+							register={register}
+							name='email'
+							type='text'
+							id='email'
+							placeholder='Enter email'
+							variant='withIcon'
+						/>
+					</div>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>
+							Password
+						</label>
+						<Input<LoginFormValues>
+							icon={padlockIcon}
+							register={register}
+							name='password'
+							type={isPasswordVisible ? 'text' : 'password'}
+							id='password'
+							placeholder='Enter password'
+							variant='withIcon'
+						>
+							<div className='absolute right-3 top-3'>
+								<button type='button' onClick={handleToggle}>
+									<Image
+										src={isPasswordVisible ? eyeOn.src : eyeOff.src}
+										className='w-4'
+										alt='Toggle visibility'
+										width={16}
+										height={16}
+									/>
+								</button>
+							</div>
+						</Input>
+					</div>
+
+					<Button
+						message='Sign in'
+						size='large'
+						disabled={isSubmitting}
+						variant='primeButton'
+					/>
+					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
+					<Link href='/join-us'>
+						<p className='text-sm text-neutral-500 font-poppins'>
+							Don&apos;t have an account?{' '}
+							<span className='text-indigo-700 font-bold cursor-pointer'>
+								Sign up
+							</span>
+						</p>
+					</Link>
+					{captchaWarning && (
+						<p className='text-sm text-red-500'>Please complete the captcha</p>
+					)}
+					{loginError && (
+						<p className='text-sm text-red-500 mt-2'>{loginError}</p>
+					)}
+					<ReCAPTCHA
+						sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
+						onChange={handleCaptchaChange}
+					/>
+				</form>
+			</div>
+		</div>
+	);
+};
+
+export default Login;
diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx
index fef925e..a7e489d 100644
--- a/src/app/login/page.tsx
+++ b/src/app/login/page.tsx
@@ -1,117 +1,11 @@
-'use client';
-import React, { useState } from 'react';
-import { useForm, SubmitHandler } from 'react-hook-form';
-import { IFormValues } from '@/shared/Input/types';
-import Image from 'next/image';
-import ReCAPTCHA from 'react-google-recaptcha';
-
-import Input from '@/shared/Input/Input';
-import Button from '@/shared/Button/Button';
-
-import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { Suspense } from 'react';
+import LoginForm from './LoginForm';
 
 const Login = () => {
-	const [captchaCompleted, setCaptchaCompleted] = useState(false);
-	const [isPasswordVisible, setPasswordVisible] = useState(false);
-
-	const {
-		register,
-		formState: { isSubmitting },
-		handleSubmit,
-	} = useForm<IFormValues>();
-
-	const onSubmit: SubmitHandler<IFormValues> = async (data) => {
-		if (!captchaCompleted) return;
-		await new Promise((resolve) => {
-			setTimeout(resolve, 1000);
-		});
-		alert(JSON.stringify(data));
-	};
-
-	const handleToggle = () => {
-		setPasswordVisible(!isPasswordVisible);
-	};
-
-	const handleCaptchaChange = (value: string | null) => {
-		setCaptchaCompleted(value ? true : false);
-	};
-
 	return (
-		<div className='min-h-screen flex items-center justify-center pb-32'>
-			<div className='flex flex-col items-center gap-5'>
-				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
-					Sign in
-				</p>
-				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
-
-				<form
-					className='flex flex-col items-center gap-4'
-					onSubmit={handleSubmit(onSubmit)}
-				>
-					<div className='flex flex-col'>
-						<label className='text-sm font-semibold font-poppins'>
-							User name
-						</label>
-						<Input
-							icon={userIcon}
-							register={register}
-							name='username'
-							type='text'
-							id='username'
-							placeholder='Enter email'
-							required
-							variant='withIcon'
-						/>
-					</div>
-					<div className='flex flex-col'>
-						<label className='text-sm font-semibold font-poppins'>
-							Password
-						</label>
-						<Input
-							icon={padlockIcon}
-							register={register}
-							name='password'
-							type={isPasswordVisible ? 'text' : 'password'}
-							id='password'
-							placeholder='Enter password'
-							required
-							variant='withIcon'
-						>
-							<div className='absolute right-3 top-3'>
-								<button type='button' onClick={handleToggle}>
-									<Image
-										src={isPasswordVisible ? eyeOn.src : eyeOff.src}
-										className='w-4'
-										alt='Toggle visibility'
-										width={16}
-										height={16}
-									/>
-								</button>
-							</div>
-						</Input>
-					</div>
-
-					<Button
-						message='Sign in'
-						size='large'
-						disabled={isSubmitting}
-						variant='primeButton'
-					/>
-					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
-					<p className='text-sm text-neutral-500 font-poppins'>
-						Don&apos;t have an account?{' '}
-						<span className='text-indigo-700 font-bold cursor-pointer'>
-							Sign up
-						</span>
-					</p>
-
-					<ReCAPTCHA
-						sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
-						onChange={handleCaptchaChange}
-					/>
-				</form>
-			</div>
-		</div>
+		<Suspense fallback={<div>Loading...</div>}>
+			<LoginForm />
+		</Suspense>
 	);
 };
 
diff --git a/src/app/login/utils.ts b/src/app/login/utils.ts
new file mode 100644
index 0000000..cb9cebb
--- /dev/null
+++ b/src/app/login/utils.ts
@@ -0,0 +1,67 @@
+import { signInWithEmailAndPassword } from 'firebase/auth';
+import { FirebaseError } from 'firebase/app';
+import { auth } from '@/../firebase/clientApp';
+import { loginSchema } from './validation';
+import { SubmitHandler } from 'react-hook-form';
+import { LoginFormValues } from '@/shared/Input/types';
+
+export type LoginResult = {
+	success: boolean;
+	error?: string;
+};
+
+export const userLogin: SubmitHandler<LoginFormValues> = async (
+	data
+): Promise<LoginResult> => {
+	try {
+		const validationResult = loginSchema.safeParse(data);
+		if (!validationResult.success) {
+			return {
+				success: false,
+				error: 'Invalid form data',
+			};
+		}
+
+		const { email, password } = validationResult.data;
+		await signInWithEmailAndPassword(auth, email, password);
+		return {
+			success: true,
+		};
+	} catch (error) {
+		if (error instanceof FirebaseError) {
+			console.log(error.code);
+			switch (error.code) {
+				case 'auth/too-many-requests':
+					return {
+						success: false,
+						error: 'Too many attempts. Try again later',
+					};
+				case 'auth/invalid-email':
+					return {
+						success: false,
+						error: 'Invalid email format',
+					};
+				case 'auth/user-disabled':
+					return {
+						success: false,
+						error: 'This account has been disabled',
+					};
+				case 'auth/invalid-credential':
+					return {
+						success: false,
+						error: 'Invalid email or password',
+					};
+				default:
+					return {
+						success: false,
+						error: 'An error occurred during login',
+					};
+			}
+		}
+
+		return {
+			success: false,
+			error: 'An unexpected error occurred',
+		};
+	}
+};
diff --git a/src/app/login/validation.ts b/src/app/login/validation.ts
new file mode 100644
index 0000000..bfd7c36
--- /dev/null
+++ b/src/app/login/validation.ts
@@ -0,0 +1,10 @@
+import { z } from 'zod';
+
+export const loginSchema = z.object({
+	email: z.string().email({
+		message: 'Email must be a valid email address',
+	}),
+	password: z.string().min(6, {
+		message: 'Password must be at least 6 characters long',
+	}),
+});
diff --git a/src/app/registration/actions.ts b/src/app/registration/actions.ts
new file mode 100644
index 0000000..7bf9de0
--- /dev/null
+++ b/src/app/registration/actions.ts
@@ -0,0 +1,59 @@
+'use server';
+import { SubmitHandler } from 'react-hook-form';
+import { FirebaseError } from 'firebase/app';
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { auth, db } from '../../../firebase/clientApp';
+import { doc, setDoc } from 'firebase/firestore';
+
+import { RegistrationFormValues } from '@/shared/Input/types';
+import { registrationSchema } from './validation';
+
+export const createUser: SubmitHandler<RegistrationFormValues> = async (
+	data
+) => {
+	try {
+		const validationResult = registrationSchema.safeParse(data);
+		if (!validationResult.success) {
+			console.log(validationResult.error);
+			return { success: false, error: validationResult.error.message };
+		}
+		const { firstName, lastName, email, specialization, password } =
+			validationResult.data;
+		const res = await createUserWithEmailAndPassword(auth, email, password);
+		const uid = res.user.uid;
+		const userProfile = {
+			uid,
+			firstName: firstName,
+			lastName: lastName,
+			email: email,
+			specialization: specialization,
+			role: 'student',
+		};
+		await setDoc(doc(db, 'users', uid), userProfile);
+		return { success: true };
+	} catch (error) {
+		if (error instanceof FirebaseError) {
+			switch (error.code) {
+				case 'auth/email-already-in-use':
+					return { success: false, error: 'Email is already registered' };
+				case 'auth/invalid-email':
+					return { success: false, error: 'Invalid email format' };
+				case 'auth/operation-not-allowed':
+					return {
+						success: false,
+						error: 'Email/password accounts are not enabled',
+					};
+				case 'auth/weak-password':
+					return { success: false, error: 'Password is too weak' };
+				default:
+					console.error('Firebase error:', error.code, error.message);
+					return {
+						success: false,
+						error: 'An error occurred during registration',
+					};
+			}
+		}
+		console.error('Unknown error:', error);
+		return { success: false, error: 'An unexpected error occurred' };
+	}
+};
diff --git a/src/app/registration/page.tsx b/src/app/registration/page.tsx
index 92c1ea2..d97b659 100644
--- a/src/app/registration/page.tsx
+++ b/src/app/registration/page.tsx
@@ -1,30 +1,46 @@
 'use client';
-import React from 'react';
-import { useForm, SubmitHandler } from 'react-hook-form';
-import { IFormValues } from '@/shared/Input/types';
+import React, { useState } from 'react';
+import { useForm } from 'react-hook-form';
+import { RegistrationFormValues } from '@/shared/Input/types';
 import Image from 'next/image';
 import Input from '@/shared/Input/Input';
 import Selector from '@/shared/Selector/Selector';
 import Button from '@/shared/Button/Button';
-
 import { regTrainee, regStudent } from '@/assets';
 import { specializations } from '@/constants/Registration/constants';
 
+import { createUser } from './actions';
+type RegistrationResponse = { success: boolean; error?: string };
+import { zodResolver } from '@hookform/resolvers/zod';
+import { registrationSchema } from './validation';
+import { useRouter } from 'next/navigation';
+//TODO handle role
 const testRole = 'Student';
 
 const Registration = () => {
+	const router = useRouter();
+	const [error, setError] = useState<string | null>(null);
+	const onSubmit = async (data: RegistrationFormValues) => {
+		try {
+			setError(null);
+			const res = (await createUser(data)) as RegistrationResponse;
+			if (!res.success) {
+				setError(res.error || 'Registration failed');
+			} else {
+				router.push('/login');
+			}
+		} catch (error) {
+			setError('An unexpected error occurred during registration');
+			console.error('Error during registration:', error);
+		}
+	};
 	const {
 		register,
 		handleSubmit,
 		formState: { errors, isSubmitting },
-	} = useForm<IFormValues>();
-
-	const onSubmit: SubmitHandler<IFormValues> = async (data) => {
-		await new Promise((resolve) => {
-			setTimeout(resolve, 1000);
-		});
-		alert(JSON.stringify(data));
-	};
+	} = useForm<RegistrationFormValues>({
+		resolver: zodResolver(registrationSchema),
+	});
 
 	const displayImage = (role: string) => {
 		return role === 'Student' ? regStudent.src : regTrainee.src;
@@ -51,7 +67,12 @@ const Registration = () => {
 						className='flex flex-col gap-6 w-[629px] min-h-fit'
 						onSubmit={handleSubmit(onSubmit)}
 					>
-						<Input
+						{error && (
+							<div className='p-4 bg-red-50 border border-red-200 rounded-lg'>
+								<p className='text-red-600 font-poppins text-sm'>{error}</p>
+							</div>
+						)}
+						<Input<RegistrationFormValues>
 							register={register}
 							label='First Name'
 							type='text'
@@ -60,12 +81,8 @@ const Registration = () => {
 							required
 							variant='transparent'
 							error={errors.firstName}
-							validation={{
-								minLength: 2,
-							}}
 						/>
-
-						<Input
+						<Input<RegistrationFormValues>
 							register={register}
 							label='Last Name'
 							type='text'
@@ -74,12 +91,8 @@ const Registration = () => {
 							required
 							variant='transparent'
 							error={errors.lastName}
-							validation={{
-								minLength: 2,
-							}}
 						/>
-
-						<Input
+						<Input<RegistrationFormValues>
 							register={register}
 							label='Email'
 							type='email'
@@ -88,12 +101,16 @@ const Registration = () => {
 							required
 							variant='transparent'
 							error={errors.email}
-							validation={{
-								pattern: {
-									value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
-									message: 'Please enter a valid email address.',
-								},
-							}}
+						/>
+						<Input<RegistrationFormValues>
+							register={register}
+							label='Password'
+							type='password'
+							name='password'
+							placeholder='Input text'
+							required
+							variant='transparent'
+							error={errors.password}
 						/>
 						<div>
 							<label className='text-neutral-700 text-md font-bold'>
diff --git a/src/app/registration/validation.ts b/src/app/registration/validation.ts
new file mode 100644
index 0000000..7d04c35
--- /dev/null
+++ b/src/app/registration/validation.ts
@@ -0,0 +1,19 @@
+import { z } from 'zod';
+
+export const registrationSchema = z.object({
+	firstName: z.string().min(2, {
+		message: 'First name must be at least 2 characters long',
+	}),
+	lastName: z.string().min(2, {
+		message: 'Last name must be at least 2 characters long',
+	}),
+	email: z.string().email({
+		message: 'Email must be a valid email address',
+	}),
+	specialization: z.string().nonempty({
+		message: 'Specialization must not be empty',
+	}),
+	password: z.string().min(6, {
+		message: 'Password must be at least 6 characters long',
+	}),
+});
diff --git a/src/components/Footer/FooterBottom/FooterBottom.tsx b/src/components/Footer/FooterBottom/FooterBottom.tsx
index 4b769aa..9b7bbd5 100644
--- a/src/components/Footer/FooterBottom/FooterBottom.tsx
+++ b/src/components/Footer/FooterBottom/FooterBottom.tsx
@@ -10,10 +10,10 @@ import {
 
 import LegalLinks from './LegalLinks/LegalLinks';
 import Selector from '@/shared/Selector/Selector';
-import { IFormValues } from '@/shared/Input/types';
+import { FormValues } from '@/shared/Input/types';
 
 const FooterBottom = () => {
-	const { register } = useForm<IFormValues>();
+	const { register } = useForm<FormValues>();
 
 	return (
 		<aside className='container mx-auto mt-10 border-t border-gray-200 pt-4 grid grid-cols-1 md:grid-cols-3 gap-4 text-center px-4 text-nowrap'>
diff --git a/src/components/Footer/NewsLetter/NewsLetter.tsx b/src/components/Footer/NewsLetter/NewsLetter.tsx
index 4d2cdf2..92a91e9 100644
--- a/src/components/Footer/NewsLetter/NewsLetter.tsx
+++ b/src/components/Footer/NewsLetter/NewsLetter.tsx
@@ -1,7 +1,7 @@
 'use client';
 import React from 'react';
 import { useForm } from 'react-hook-form';
-import { IFormValues } from '@/shared/Input/types';
+import { FormValues } from '@/shared/Input/types';
 
 import { emailIcon } from '@/assets';
 
@@ -9,7 +9,7 @@ import Button from '@/shared/Button/Button';
 import Input from '@/shared/Input/Input';
 
 const NewsLetter = () => {
-	const { register } = useForm<IFormValues>();
+	const { register } = useForm<FormValues>();
 	const handleClick = () => {};
 	return (
 		<section
diff --git a/src/constants/constants.ts b/src/constants/constants.ts
index 161e746..6aacb8f 100644
--- a/src/constants/constants.ts
+++ b/src/constants/constants.ts
@@ -57,3 +57,7 @@ export const BOX_MOCKED_DATA = [
 		duration: 5,
 	},
 ];
+
+export const COOKIE_NAME = 'firebase-auth-token';
+export const COOKIE_MAX_AGE = 30 * 24 * 60 * 60;
+export const TOKEN_REFRESH_INTERVAL = 10 * 60 * 1000;
diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx
new file mode 100644
index 0000000..f0104ad
--- /dev/null
+++ b/src/context/AuthContext.tsx
@@ -0,0 +1,110 @@
+'use client';
+
+import {
+	createContext,
+	useContext,
+	ReactNode,
+	useEffect,
+	useCallback,
+} from 'react';
+import { useRouter } from 'next/navigation';
+import { useAuthState } from 'react-firebase-hooks/auth';
+import { signOut } from 'firebase/auth';
+import nookies from 'nookies';
+import { auth } from '@/../firebase/clientApp';
+import {
+	COOKIE_NAME,
+	COOKIE_MAX_AGE,
+	TOKEN_REFRESH_INTERVAL,
+} from '@/constants/constants';
+import { AuthContextType } from '@/types';
+
+const AuthContext = createContext<AuthContextType | null>(null);
+
+export const AuthProvider = ({ children }: { children: ReactNode }) => {
+	const [user, loading, error] = useAuthState(auth);
+	const router = useRouter();
+
+	const setCookie = useCallback(async (token: string) => {
+		try {
+			nookies.set(undefined, COOKIE_NAME, token, {
+				maxAge: COOKIE_MAX_AGE,
+				path: '/',
+				secure: process.env.NODE_ENV === 'production',
+				sameSite: 'strict',
+			});
+			return true;
+		} catch (error) {
+			console.error('Error setting auth cookie:', error);
+			return false;
+		}
+	}, []);
+
+	const clearCookie = useCallback(() => {
+		try {
+			nookies.destroy(undefined, COOKIE_NAME, { path: '/' });
+			return true;
+		} catch (error) {
+			console.error('Error clearing auth cookie:', error);
+			return false;
+		}
+	}, []);
+
+	useEffect(() => {
+		const syncToken = async () => {
+			if (!user) {
+				if (!loading) {
+					clearCookie();
+				}
+				return;
+			}
+
+			try {
+				const token = await user.getIdToken(true);
+				await setCookie(token);
+			} catch (error) {
+				console.error('Error syncing auth token:', error);
+				clearCookie();
+			}
+		};
+
+		syncToken();
+		const refreshInterval = setInterval(syncToken, TOKEN_REFRESH_INTERVAL);
+
+		return () => clearInterval(refreshInterval);
+	}, [user, loading, setCookie, clearCookie]);
+
+	const logout = useCallback(async () => {
+		try {
+			await signOut(auth);
+			clearCookie();
+			router.push('/login');
+		} catch (error) {
+			console.error('Error during logout:', error);
+			throw error;
+		}
+	}, [router, clearCookie]);
+
+	const value: AuthContextType = {
+		user: user || null,
+		loading,
+		error,
+		logout,
+		isAuthenticated: !!user,
+	};
+
+	return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
+};
+
+export const useAuth = () => {
+	const context = useContext(AuthContext);
+	if (!context) {
+		throw new Error('useAuth must be used within an AuthProvider');
+	}
+	return context;
+};
+
+export const useIsAuthenticated = () => {
+	const { isAuthenticated, loading } = useAuth();
+	return { isAuthenticated, loading };
+};
diff --git a/src/middleware.ts b/src/middleware.ts
new file mode 100644
index 0000000..7609134
--- /dev/null
+++ b/src/middleware.ts
@@ -0,0 +1,46 @@
+import { NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+import { COOKIE_NAME } from '@/constants/constants';
+
+const publicPaths = [
+	'/',
+	'/join-us',
+	'/blog',
+	'/pricing',
+	'/about',
+	'/login',
+	'/registration',
+];
+
+const isPublicPath = (path: string) => {
+	return publicPaths.some((publicPath) => {
+		if (publicPath === path) return true;
+		return path.startsWith(`${publicPath}/`);
+	});
+};
+
+export async function middleware(request: NextRequest) {
+	const { pathname } = request.nextUrl;
+
+	if (
+		isPublicPath(pathname) ||
+		pathname.startsWith('/_next/') ||
+		pathname.includes('.')
+	) {
+		return NextResponse.next();
+	}
+
+	const authCookie = request.cookies.get(COOKIE_NAME)?.value;
+
+	if (!authCookie) {
+		const redirectTo = encodeURIComponent(pathname);
+		return NextResponse.redirect(
+			new URL(`/login?returnUrl=${redirectTo}`, request.url)
+		);
+	}
+	return NextResponse.next();
+}
+
+export const config = {
+	matcher: ['/((?!_next|_vercel|fonts|images|public|api).*)'],
+};
diff --git a/src/shared/Input/Input.tsx b/src/shared/Input/Input.tsx
index 11f0234..b1b891b 100644
--- a/src/shared/Input/Input.tsx
+++ b/src/shared/Input/Input.tsx
@@ -6,7 +6,6 @@ import {
 	RegisterOptions,
 	FieldError,
 } from 'react-hook-form';
-import { IFormValues } from './types';
 import { VariantProps, cva } from 'class-variance-authority';
 import { cn } from '@/lib/utils';
 
@@ -31,22 +30,28 @@ const inputVariants = cva(
 	}
 );
 
-interface InputProps
-	extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>,
+interface InputProps<
+	TFormValues extends Record<string, any> = Record<string, any>,
+> extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>,
 		VariantProps<typeof inputVariants> {
 	icon?: string;
 	type: string;
 	label?: string;
-	name: Path<IFormValues>;
+	name: Path<TFormValues>;
 	placeholder: string;
 	required?: boolean;
 	children?: React.ReactNode;
-	register: UseFormRegister<IFormValues>;
-	validation?: RegisterOptions<IFormValues>;
+	register: UseFormRegister<TFormValues>;
+	validation?: RegisterOptions<TFormValues>;
 	error?: FieldError;
 }
 
-const Input = ({ className, size, variant, ...props }: InputProps) => {
+const Input = <TFormValues extends Record<string, any> = Record<string, any>>({
+	className,
+	size,
+	variant,
+	...props
+}: InputProps<TFormValues>) => {
 	return (
 		<div className='relative flex items-center'>
 			{props.icon && (
@@ -58,7 +63,6 @@ const Input = ({ className, size, variant, ...props }: InputProps) => {
 					height={20}
 				/>
 			)}
-
 			<div className='w-full'>
 				<label
 					className={cn(
diff --git a/src/shared/Input/types.ts b/src/shared/Input/types.ts
index c500315..2ebcff0 100644
--- a/src/shared/Input/types.ts
+++ b/src/shared/Input/types.ts
@@ -1,9 +1,17 @@
-export interface IFormValues {
-	username: string;
+export type LoginFormValues = {
+	email: string;
 	password: string;
+};
+
+export type RegistrationFormValues = {
 	firstName: string;
 	lastName: string;
 	email: string;
 	specialization: string;
-	language: string;
-}
+	password: string;
+};
+
+export type FormValues =
+	| LoginFormValues
+	| RegistrationFormValues
+	| Record<string, any>;
diff --git a/src/shared/Selector/Selector.tsx b/src/shared/Selector/Selector.tsx
index 28474cf..48b7879 100644
--- a/src/shared/Selector/Selector.tsx
+++ b/src/shared/Selector/Selector.tsx
@@ -1,17 +1,21 @@
 import React from 'react';
 import { UseFormRegister, Path } from 'react-hook-form';
 
-import { IFormValues } from '../Input/types';
-
-interface SelectorProps {
-	name: Path<IFormValues>;
+type SelectorProps<
+	TFormValues extends Record<string, any> = Record<string, any>,
+> = {
+	name: Path<TFormValues>;
 	className?: string;
 	value?: string;
 	required?: boolean;
 	options: string[];
-	register: UseFormRegister<IFormValues>;
-}
-const Selector = (props: SelectorProps) => {
+	register: UseFormRegister<TFormValues>;
+};
+const Selector = <
+	TFormValues extends Record<string, any> = Record<string, any>,
+>(
+	props: SelectorProps<TFormValues>
+) => {
 	return (
 		<select
 			{...props.register(props.name)}
diff --git a/src/types.ts b/src/types.ts
index 4ce9024..b2e4c3c 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,3 +1,4 @@
+import { User } from 'firebase/auth';
 import { StaticImageData } from 'next/image';
 
 export type Blogs = {
@@ -21,3 +22,11 @@ export type Links = {
 	href: string;
 	label: string;
 };
+
+export type AuthContextType = {
+	user: User | null;
+	loading: boolean;
+	error: Error | undefined;
+	logout: () => Promise<void>;
+	isAuthenticated: boolean;
+};


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 11**

<details>
<summary>🧹 Nitpick comments (11)</summary><blockquote>

<details>
<summary>src/app/login/validation.ts (1)</summary><blockquote>

`1-10`: **Consider strengthening the password requirements**

While the validation schema is well-structured and provides clear error messages, modern security standards typically recommend passwords with at least 8 characters and additional complexity requirements (uppercase, lowercase, numbers, special characters).


```diff
 password: z.string().min(6, {
-		message: 'Password must be at least 6 characters long',
+		message: 'Password must be at least 8 characters long',
 	}),
```

You could also consider adding more validation rules:

```javascript
password: z.string()
  .min(8, { message: 'Password must be at least 8 characters long' })
  .regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter' })
  .regex(/[0-9]/, { message: 'Password must contain at least one number' })
  .regex(/[^A-Za-z0-9]/, { message: 'Password must contain at least one special character' }),
```

</blockquote></details>
<details>
<summary>src/types.ts (1)</summary><blockquote>

`26-32`: **Well-defined authentication context type**

The AuthContextType provides a clear interface for the authentication context with appropriate properties for managing user state, loading status, errors, and authentication actions.

One suggestion: consider adding a login method to complement the logout function for a more symmetrical API.



```diff
 export type AuthContextType = {
 	user: User | null;
 	loading: boolean;
 	error: Error | undefined;
 	logout: () => Promise<void>;
+	login: (email: string, password: string) => Promise<void>;
 	isAuthenticated: boolean;
 };
```

</blockquote></details>
<details>
<summary>src/shared/Input/types.ts (1)</summary><blockquote>

`13-16`: **Consider the tradeoffs of using Record<string, any> in FormValues union.**

While this provides flexibility, it reduces type safety by allowing any key-value pairs.


Consider using a more specific approach to maintain better type safety:

```diff
export type FormValues =
	| LoginFormValues
	| RegistrationFormValues
-	| Record<string, any>;
+	| NewsletterFormValues;  // Define specific types instead of Record<string, any>
```

</blockquote></details>
<details>
<summary>src/app/registration/page.tsx (1)</summary><blockquote>

`87-93`: **Add generic typing to the Selector component.**

Other form components use generic typing for consistency and type safety.


Update the Selector component to use generics like the Input components:

```diff
<Selector
+   <RegistrationFormValues>
    name='specialization'
    register={register}
    className='w-full'
    options={specializations}
    required
+   error={errors.specialization}
/>
```

</blockquote></details>
<details>
<summary>src/app/registration/actions.ts (1)</summary><blockquote>

`28-35`: **Consider making the user role configurable**

The user profile has a hardcoded role of 'student', which might limit the flexibility of the registration system.


Consider making the role configurable:

```diff
const userProfile = {
  uid,
  firstName: firstName,
  lastName: lastName,
  email: email,
  specialization: specialization,
- role: 'student',
+ role: data.role || 'student', // Default to 'student' if not provided
};
```

</blockquote></details>
<details>
<summary>src/app/login/utils.ts (2)</summary><blockquote>

`31-33`: **Remove console.log from production code**

Logging sensitive information like error codes to the console in production code is not recommended and could expose debugging information to users.


Remove the console.log statement:

```diff
if (error instanceof FirebaseError) {
-  console.log(error.code);
  switch (error.code) {
```

---

`61-65`: **Handle non-Firebase errors more specifically**

The final catch-all error handler doesn't differentiate between different types of non-Firebase errors, which could make debugging more difficult.


Consider adding more specific error handling:

```diff
- return {
-   success: false,
-   error: 'An unexpected error occurred',
- };
+ const errorMessage = error instanceof Error 
+   ? `Error: ${error.message}` 
+   : 'An unexpected error occurred';
+ console.error('Login error:', error);
+ return {
+   success: false,
+   error: errorMessage,
+ };
```

</blockquote></details>
<details>
<summary>src/middleware.ts (1)</summary><blockquote>

`14-19`: **Simplify public path checking logic**

The current implementation of `isPublicPath` is more complex than needed. It can be simplified for better readability.


Use `startsWith` consistently:

```diff
const isPublicPath = (path: string) => {
-  return publicPaths.some((publicPath) => {
-    if (publicPath === path) return true;
-    return path.startsWith(`${publicPath}/`);
-  });
+  return publicPaths.some((publicPath) => 
+    path === publicPath || path.startsWith(`${publicPath}/`)
+  );
};
```

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (2)</summary><blockquote>

`53-55`: **Simplify the CAPTCHA change handler**

The ternary expression is unnecessarily verbose and can be simplified.


```diff
-	const handleCaptchaChange = (value: string | null) => {
-		setCaptchaCompleted(value ? true : false);
-	};
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(!!value);
+	};
```

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

---

`114-119`: **Consider showing loading state on the submit button**

The form tracks submission state with `isSubmitting`, and the button is properly disabled during submission. However, it would improve user experience to also show a loading indicator.


```diff
 <Button
   message='Sign in'
   size='large'
   disabled={isSubmitting}
   variant='primeButton'
+  isLoading={isSubmitting}
 />
```

</blockquote></details>
<details>
<summary>src/context/AuthContext.tsx (1)</summary><blockquote>

`88-94`: **Consider using useReducer for complex state management**

For a complex authentication state that includes multiple related values, consider using `useReducer` instead of multiple state variables. This would make the state transitions more explicit and easier to manage.


This is just a suggestion for future refactoring as the current implementation is already well-structured.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 11f69d9b7b8d0328f82508fd0ce3ca457ceac9bf and 7794e4d709381d47d7d98cd7b11ae896a70ea34f.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `bun.lockb` is excluded by `!**/bun.lockb`

</details>

<details>
<summary>📒 Files selected for processing (19)</summary>

* `firebase/clientApp.ts` (1 hunks)
* `package.json` (1 hunks)
* `src/app/layout.tsx` (2 hunks)
* `src/app/login/LoginForm.tsx` (1 hunks)
* `src/app/login/page.tsx` (1 hunks)
* `src/app/login/utils.ts` (1 hunks)
* `src/app/login/validation.ts` (1 hunks)
* `src/app/registration/actions.ts` (1 hunks)
* `src/app/registration/page.tsx` (4 hunks)
* `src/app/registration/validation.ts` (1 hunks)
* `src/components/Footer/FooterBottom/FooterBottom.tsx` (1 hunks)
* `src/components/Footer/NewsLetter/NewsLetter.tsx` (1 hunks)
* `src/constants/constants.ts` (1 hunks)
* `src/context/AuthContext.tsx` (1 hunks)
* `src/middleware.ts` (1 hunks)
* `src/shared/Input/Input.tsx` (1 hunks)
* `src/shared/Input/types.ts` (1 hunks)
* `src/shared/Selector/Selector.tsx` (1 hunks)
* `src/types.ts` (2 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (8)</summary>

<details>
<summary>src/components/Footer/FooterBottom/FooterBottom.tsx (1)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `FormValues` (13-16)

</details>

</blockquote></details>
<details>
<summary>src/components/Footer/NewsLetter/NewsLetter.tsx (1)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `FormValues` (13-16)

</details>

</blockquote></details>
<details>
<summary>src/app/layout.tsx (1)</summary><blockquote>

<details>
<summary>src/context/AuthContext.tsx (1)</summary>

* `AuthProvider` (24-97)

</details>

</blockquote></details>
<details>
<summary>src/app/registration/page.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `RegistrationFormValues` (6-11)

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

* `registrationSchema` (3-16)

</details>
<details>
<summary>src/app/registration/actions.ts (1)</summary>

* `createUser` (10-41)

</details>

</blockquote></details>
<details>
<summary>src/app/login/utils.ts (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `LoginFormValues` (1-4)

</details>
<details>
<summary>src/app/login/validation.ts (1)</summary>

* `loginSchema` (3-10)

</details>
<details>
<summary>firebase/clientApp.ts (1)</summary>

* `auth` (16-16)

</details>

</blockquote></details>
<details>
<summary>src/app/registration/actions.ts (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `RegistrationFormValues` (6-11)

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

* `registrationSchema` (3-16)

</details>
<details>
<summary>firebase/clientApp.ts (2)</summary>

* `auth` (16-16)
* `db` (17-17)

</details>

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `LoginFormValues` (1-4)

</details>
<details>
<summary>src/app/login/validation.ts (1)</summary>

* `loginSchema` (3-10)

</details>
<details>
<summary>src/app/login/utils.ts (2)</summary>

* `LoginResult` (8-11)
* `userLogin` (13-67)

</details>

</blockquote></details>
<details>
<summary>src/context/AuthContext.tsx (3)</summary><blockquote>

<details>
<summary>src/types.ts (1)</summary>

* `AuthContextType` (26-32)

</details>
<details>
<summary>firebase/clientApp.ts (1)</summary>

* `auth` (16-16)

</details>
<details>
<summary>src/constants/constants.ts (3)</summary>

* `COOKIE_NAME` (61-61)
* `COOKIE_MAX_AGE` (62-62)
* `TOKEN_REFRESH_INTERVAL` (63-63)

</details>

</blockquote></details>

</details><details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>src/app/login/LoginForm.tsx</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (23)</summary><blockquote>

<details>
<summary>src/components/Footer/NewsLetter/NewsLetter.tsx (1)</summary>

`4-4`: **Type update aligns with application-wide form handling refactoring.**

The change from `IFormValues` to the new union type `FormValues` maintains compatibility while supporting the new authentication system's form types. This is a good approach as it centralizes form type definitions.



Also applies to: 12-12

</details>
<details>
<summary>src/components/Footer/FooterBottom/FooterBottom.tsx (1)</summary>

`13-13`: **Type update aligns with application-wide form handling refactoring.**

The change from `IFormValues` to `FormValues` ensures consistent typing across the application's form components. Good consistency with other form handling components.



Also applies to: 16-16

</details>
<details>
<summary>package.json (1)</summary>

`20-20`: **Appropriate dependencies added for authentication implementation.**

The added dependencies align well with the authentication feature:
- `@hookform/resolvers`: Integrates validation libraries with react-hook-form
- `nookies`: Handles secure cookie management for authentication tokens 
- `zod`: Provides schema validation for form inputs

All versions appear to be recent and stable.



Also applies to: 28-28, 37-37

</details>
<details>
<summary>src/app/layout.tsx (1)</summary>

`7-7`: **Well-implemented global authentication context.**

Wrapping the entire application in the `AuthProvider` is the correct approach for providing authentication state throughout the component tree. The implementation properly handles token synchronization, cookie management, and logout functionality.



Also applies to: 32-36

</details>
<details>
<summary>src/app/login/page.tsx (1)</summary>

`1-8`: **Great refactoring - improved separation of concerns**

The Login page has been nicely simplified by delegating the form rendering and logic to a dedicated LoginForm component wrapped in a Suspense boundary. This approach improves maintainability and follows the single responsibility principle.

</details>
<details>
<summary>firebase/clientApp.ts (1)</summary>

`15-17`: **Good refactoring to named exports**

Switching from default exports to named exports improves code clarity and maintainability. This change allows for more explicit imports in other files.

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

`1-16`: **Good implementation of a validation schema using Zod.**

The schema correctly validates the registration form fields with appropriate constraints and user-friendly error messages.



However, I notice that password validation is missing from the schema, while the action function in `src/app/registration/actions.ts` uses a hardcoded password. Consider adding password validation to ensure secure user registration:

```diff
export const registrationSchema = z.object({
	firstName: z.string().min(2, {
		message: 'First name must be at least 2 characters long',
	}),
	lastName: z.string().min(2, {
		message: 'Last name must be at least 2 characters long',
	}),
	email: z.string().email({
		message: 'Email must be a valid email address',
	}),
	specialization: z.string().nonempty({
		message: 'Specialization must not be empty',
	}),
+	password: z.string().min(8, {
+		message: 'Password must be at least 8 characters long',
+	}),
+	confirmPassword: z.string()
}).refine(data => data.password === data.confirmPassword, {
+	message: "Passwords don't match",
+	path: ["confirmPassword"],
});
```

</details>
<details>
<summary>src/constants/constants.ts (1)</summary>

`61-63`: **Well-defined authentication constants with clear values.**

The constants use descriptive names and appropriate values for authentication token management:
- 30-day cookie expiration is a good balance between convenience and security
- 10-minute token refresh interval follows security best practices

</details>
<details>
<summary>src/shared/Input/types.ts (1)</summary>

`6-11`: **Well-structured registration form type.**

The `RegistrationFormValues` type correctly maps to the fields in your registration schema and form.



However, I notice that password fields are missing from this type while the registration form would typically require them. Consider updating this type to include password fields:

```diff
export type RegistrationFormValues = {
	firstName: string;
	lastName: string;
	email: string;
	specialization: string;
+	password: string;
+	confirmPassword: string;
};
```

</details>
<details>
<summary>src/app/registration/page.tsx (2)</summary>

`3-14`: **Good use of Zod schema validation and resolver integration.**

The integration of schema-based validation centralizes validation logic and improves form handling.

---

`24-26`: **Good implementation of form validation with zodResolver.**

Using the zodResolver with useForm provides consistent validation based on your schema.

</details>
<details>
<summary>src/shared/Selector/Selector.tsx (1)</summary>

`4-18`: **LGTM! Great improvement to component type flexibility**

The changes to make `Selector` component generic improves type safety and reusability across different form types. This is a good practice that allows the component to be used with various form data structures.

</details>
<details>
<summary>src/middleware.ts (1)</summary>

`43-45`: **Ensure matcher pattern is comprehensive**

The current matcher excludes certain paths, but there might be other paths that should be excluded.


The matcher pattern appropriately excludes Next.js internals and static files. Just ensure that any future API routes or other special paths that don't require authentication are properly handled.

</details>
<details>
<summary>src/shared/Input/Input.tsx (3)</summary>

`33-35`: **Great use of generics to enhance component flexibility!**

The `InputProps` interface now uses a generic type parameter `TFormValues` constrained to `Record<string, any>`, making the component reusable across different form types. This is a good design decision that aligns with the separation of form value types mentioned in the summary.

---

`40-46`: **Good type safety implementation**

The generic type is appropriately applied to the form-related properties like `name`, `register`, and `validation`. This ensures type safety when the component is used with different form schemas.

---

`49-54`: **Well-implemented generic functional component**

The `Input` component is properly declared as a generic functional component, correctly using the same generic type parameter as the props interface. This implementation ensures that TypeScript will enforce correct prop types based on the form values type provided when using the component.

</details>
<details>
<summary>src/app/login/LoginForm.tsx (3)</summary>

`17-30`: **Well-structured state management and form setup**

Good implementation of the login form using react-hook-form with zod validation. The state variables are well-organized and handle different aspects of the form (CAPTCHA status, password visibility, error messaging).

---

`31-47`: **Comprehensive form submission handler**

The `onSubmit` function correctly handles:
1. CAPTCHA verification
2. Form data validation
3. Authentication via the userLogin function
4. Success/error handling and redirection

The returnUrl handling for redirection after login is a nice touch for user experience.

---

`133-136`: <details>
<summary>❓ Verification inconclusive</summary>

**Verify RECAPTCHA site key availability**

Make sure the RECAPTCHA site key environment variable is properly set. If the environment variable is missing, the CAPTCHA won't work correctly.

---

🏁 Script executed:

```shell
#!/bin/bash
# Check if the RECAPTCHA environment variable is set in the .env files
if grep -q "NEXT_PUBLIC_RECAPTCHA_SITE_KEY" .env*; then
  echo "✅ RECAPTCHA site key is defined in .env file"
else
  echo "❌ RECAPTCHA site key is not defined in any .env file"
  echo "Please add NEXT_PUBLIC_RECAPTCHA_SITE_KEY to your .env file"
fi
```

Length of output: 331

---



</details>

**Ensure RECAPTCHA site key is configured**

File: `src/app/login/LoginForm.tsx` Lines: 133–136

```jsx
<ReCAPTCHA
  sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
  onChange={handleCaptchaChange}
/>
```

We didn’t find any `.env*` files in the repo—Next.js will only load env vars from local files (e.g. `.env.local`, `.env.development`) or your deployment settings. Please:

- Add `NEXT_PUBLIC_RECAPTCHA_SITE_KEY=your_site_key` to a local `.env.local` (ensure this file is git-ignored).  
- Configure the same key in your hosting/CI environment (Vercel, Netlify, etc.).  
- Optionally verify at runtime (e.g. `console.log(process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY)`) to confirm the key is available.

</details>
<details>
<summary>src/context/AuthContext.tsx (4)</summary>

`28-41`: **Well-implemented secure cookie handling**

The `setCookie` function properly sets the authentication cookie with appropriate security options:
- Setting the max age from constants
- Using the secure flag in production
- Setting sameSite to 'strict'
- Proper error handling

This implementation follows security best practices for cookie management.

---

`53-75`: **Robust token synchronization with refresh mechanism**

The token synchronization logic is well-implemented:
1. Clears the cookie when the user is not authenticated
2. Refreshes the token and updates the cookie when authenticated
3. Sets up an interval to periodically refresh the token
4. Properly cleans up the interval on component unmount

This ensures the authentication state remains valid and secure.

---

`77-86`: **Comprehensive logout implementation**

The logout function handles all necessary steps:
1. Signs out from Firebase
2. Clears the authentication cookie
3. Redirects to the login page
4. Provides proper error handling

This ensures a clean logout process with no lingering authentication state.

---

`99-105`: **Clear error message for context usage**

The `useAuth` hook includes a helpful error message when used outside of an `AuthProvider`. This will make debugging easier for developers using this hook incorrectly.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-05-02T12:57:46Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 1**

<details>
<summary>♻️ Duplicate comments (1)</summary><blockquote>

<details>
<summary>src/app/login/LoginForm.tsx (1)</summary><blockquote>

`121-126`: _🛠️ Refactor suggestion_

**Add navigation to the Sign up link**

The "Sign up" text is styled as a clickable element but doesn't have any navigation functionality. Consider adding a link to the registration page.



```diff
+import Link from 'next/link';

...

-<p className='text-sm text-neutral-500 font-poppins'>
-	Don&apos;t have an account?{' '}
-	<span className='text-indigo-700 font-bold cursor-pointer'>
-		Sign up
-	</span>
-</p>
+<p className='text-sm text-neutral-500 font-poppins'>
+	Don&apos;t have an account?{' '}
+	<Link href="/registration" className='text-indigo-700 font-bold'>
+		Sign up
+	</Link>
+</p>
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (4)</summary><blockquote>

<details>
<summary>src/app/login/LoginForm.tsx (4)</summary><blockquote>

`53-55`: **Simplify boolean conversion in handleCaptchaChange**

The ternary operator here is unnecessary as `value ? true : false` can be simplified.


```diff
const handleCaptchaChange = (value: string | null) => {
-  setCaptchaCompleted(value ? true : false);
+  setCaptchaCompleted(!!value);
};
```

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

---

`133-136`: **Reposition CAPTCHA for better visibility**

The CAPTCHA is currently placed at the bottom of the form after error messages, making it easy to miss. Consider placing it before the submit button for better user experience.


```diff
-					<Button
-						message='Sign in'
-						size='large'
-						disabled={isSubmitting}
-						variant='primeButton'
-					/>
-					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
-					<p className='text-sm text-neutral-500 font-poppins'>
-						Don&apos;t have an account?{' '}
-						<span className='text-indigo-700 font-bold cursor-pointer'>
-							Sign up
-						</span>
-					</p>
-					{captchaWarning && (
-						<p className='text-sm text-red-500'>Please complete the captcha</p>
-					)}
-					{loginError && (
-						<p className='text-sm text-red-500 mt-2'>{loginError}</p>
-					)}
-					<ReCAPTCHA
-						sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
-						onChange={handleCaptchaChange}
-					/>
+					<ReCAPTCHA
+						sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
+						onChange={handleCaptchaChange}
+					/>
+					{captchaWarning && (
+						<p className='text-sm text-red-500'>Please complete the captcha</p>
+					)}
+					<Button
+						message='Sign in'
+						size='large'
+						disabled={isSubmitting}
+						variant='primeButton'
+					/>
+					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
+					<p className='text-sm text-neutral-500 font-poppins'>
+						Don&apos;t have an account?{' '}
+						<span className='text-indigo-700 font-bold cursor-pointer'>
+							Sign up
+						</span>
+					</p>
+					{loginError && (
+						<p className='text-sm text-red-500 mt-2'>{loginError}</p>
+					)}
```

---

`114-119`: **Add loading indicator to the submit button**

The button is correctly disabled during submission, but there's no visual indication that the form is being processed. Consider adding a loading indicator.


```diff
<Button
-  message='Sign in'
+  message={isSubmitting ? 'Signing in...' : 'Sign in'}
  size='large'
  disabled={isSubmitting}
  variant='primeButton'
/>
```

---

`36-37`: **Consider better data validation**

The check for `!data` may be redundant since the form validation should prevent submission with invalid data. If you want to keep it as a safeguard, consider adding a more specific error message.


```diff
-		if (!data) return;
+		if (!data) {
+			setLoginError("Form data is invalid. Please try again.");
+			return;
+		}
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 7794e4d709381d47d7d98cd7b11ae896a70ea34f and bb01b519936109243bb2692cba34f195ff5ca206.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/app/login/LoginForm.tsx` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>src/app/login/LoginForm.tsx</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>src/app/login/LoginForm.tsx (1)</summary>

`1-143`: **Overall implementation looks good**

The login form is well-structured with proper form validation, error handling, and user feedback. The use of react-hook-form with zod validation provides a robust validation system.

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-05-02T13:10:08Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 1**

<details>
<summary>♻️ Duplicate comments (3)</summary><blockquote>

<details>
<summary>src/app/registration/page.tsx (1)</summary><blockquote>

`16-17`: _⚠️ Potential issue_

**Address the unresolved `TODO` for dynamic role handling**

The hardcoded `testRole = 'Student'` is still present. You need to implement proper role selection logic.



Consider adding a role selector to the form:

```diff
- //TODO handle role
- const testRole = 'Student';
+ // Role selection state
+ const [role, setRole] = useState<'Student' | 'Teacher'>('Student');
```

Then add a role selector to your form:

```jsx
<div>
  <label className='text-neutral-700 text-md font-bold'>
    Role
  </label>
  <Selector
    name='role'
    register={register}
    className='w-full'
    options={[
      { label: 'Student', value: 'Student' },
      { label: 'Teacher', value: 'Teacher' }
    ]}
    onChange={(e) => setRole(e.target.value)}
    value={role}
    required
  />
</div>
```

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (2)</summary><blockquote>

`64-68`: _🛠️ Refactor suggestion_

**Clarify validation error message.**

The current error message suggests authentication failure ("wrong username or password"), but it's actually shown for form validation issues before submission. This can confuse users.



```diff
{(errors.email || errors.password) && (
  <p className='text-red-600 font-poppins font-semibold inline-block'>
-    You're entered either wrong username or password
+    Please enter a valid email and password
  </p>
)}
```

---

`121-126`: _🛠️ Refactor suggestion_

**Add navigation to the Sign up link.**

The "Sign up" text is styled as a clickable element but doesn't have any navigation functionality. Consider adding a link to the registration page.



```diff
-	<p className='text-sm text-neutral-500 font-poppins'>
-		Don&apos;t have an account?{' '}
-		<span className='text-indigo-700 font-bold cursor-pointer'>
-			Sign up
-		</span>
-	</p>
+	<p className='text-sm text-neutral-500 font-poppins'>
+		Don&apos;t have an account?{' '}
+		<span 
+			className='text-indigo-700 font-bold cursor-pointer'
+			onClick={() => router.push('/registration')}
+		>
+			Sign up
+		</span>
+	</p>
```

Or, better yet, use Next.js Link component:

```diff
+import Link from 'next/link';

...

-	<p className='text-sm text-neutral-500 font-poppins'>
-		Don&apos;t have an account?{' '}
-		<span className='text-indigo-700 font-bold cursor-pointer'>
-			Sign up
-		</span>
-	</p>
+	<p className='text-sm text-neutral-500 font-poppins'>
+		Don&apos;t have an account?{' '}
+		<Link href="/registration" className='text-indigo-700 font-bold'>
+			Sign up
+		</Link>
+	</p>
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (4)</summary><blockquote>

<details>
<summary>src/app/registration/validation.ts (1)</summary><blockquote>

`1-19`: **Good implementation of form validation with Zod**

The validation schema is well-structured with clear error messages for each field. This is a good implementation of form validation using Zod.

However, consider enhancing the password validation to enforce stronger security requirements:

```diff
password: z.string().min(6, {
	message: 'Password must be at least 6 characters long',
}),
+ // Add more password validation rules
+ // .regex(/[A-Z]/, { message: 'Password must contain at least one uppercase letter' })
+ // .regex(/[0-9]/, { message: 'Password must contain at least one number' })
+ // .regex(/[^a-zA-Z0-9]/, { message: 'Password must contain at least one special character' })
```

Also, consider adding validation for password confirmation to ensure users don't make typing mistakes:

```typescript
password: z.string().min(6, {
  message: 'Password must be at least 6 characters long',
}),
confirmPassword: z.string(),
}).refine((data) => data.password === data.confirmPassword, {
  message: "Passwords don't match",
  path: ["confirmPassword"],
});
```

</blockquote></details>
<details>
<summary>src/app/registration/page.tsx (1)</summary><blockquote>

`83-92`: **Password field added correctly**

Good job adding the password field to the form. However, consider adding a confirm password field to ensure users don't make typing mistakes:

```jsx
<Input<RegistrationFormValues>
  register={register}
  label='Confirm Password'
  type='password'
  name='confirmPassword'
  placeholder='Confirm password'
  required
  variant='transparent'
  error={errors.confirmPassword}
/>
```

This would work in conjunction with the schema refinement suggested in the validation.ts file.

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (2)</summary><blockquote>

`54-55`: **Simplify the CAPTCHA change handler.**

The conditional expression to set the CAPTCHA completion state can be simplified for better readability.


```diff
-	const handleCaptchaChange = (value: string | null) => {
-		setCaptchaCompleted(value ? true : false);
-	};
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(!!value);
+	};
```

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

---

`133-136`: **Consider adding an accessible label to the CAPTCHA.**

The reCAPTCHA component lacks an accessible label, which could impact users with screen readers.


```diff
<ReCAPTCHA
+	aria-label="Security verification"
	sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
	onChange={handleCaptchaChange}
/>
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between bb01b519936109243bb2692cba34f195ff5ca206 and cfca95f128cb72c3e37a5c02c3e5e546bbcad89e.

</details>

<details>
<summary>📒 Files selected for processing (7)</summary>

* `src/app/login/LoginForm.tsx` (1 hunks)
* `src/app/login/utils.ts` (1 hunks)
* `src/app/login/validation.ts` (1 hunks)
* `src/app/registration/actions.ts` (1 hunks)
* `src/app/registration/page.tsx` (5 hunks)
* `src/app/registration/validation.ts` (1 hunks)
* `src/shared/Input/types.ts` (1 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary>

* src/app/registration/actions.ts
* src/app/login/utils.ts
* src/shared/Input/types.ts

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (2)</summary>

<details>
<summary>src/app/registration/page.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `RegistrationFormValues` (6-12)

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

* `registrationSchema` (3-19)

</details>
<details>
<summary>src/app/registration/actions.ts (1)</summary>

* `createUser` (10-40)

</details>

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `LoginFormValues` (1-4)

</details>
<details>
<summary>src/app/login/validation.ts (1)</summary>

* `loginSchema` (3-10)

</details>
<details>
<summary>src/app/login/utils.ts (2)</summary>

* `userLogin` (13-67)
* `LoginResult` (8-11)

</details>

</blockquote></details>

</details><details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>src/app/login/LoginForm.tsx</summary>

[error] 54-54: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (5)</summary><blockquote>

<details>
<summary>src/app/registration/page.tsx (3)</summary>

`24-26`: **Good implementation of form validation with Zod resolver**

The integration of Zod validation with react-hook-form using zodResolver is a good practice that ensures type-safe form validation.

---

`51-51`: **Form now properly submits to the createUser action**

The form now correctly submits to the centralized createUser action, which includes proper validation and Firebase integration.

---

`53-82`: **Generic typing for form inputs is well implemented**

The use of generic typing `<RegistrationFormValues>` with the Input components is a good practice for type safety.

</details>
<details>
<summary>src/app/login/validation.ts (1)</summary>

`1-10`: **Well-structured validation schema with appropriate constraints.**

This Zod schema implementation provides clear validation rules for the login form with helpful error messages for users. The email validation ensures proper format, while the password requirement of at least 6 characters provides basic security.

</details>
<details>
<summary>src/app/login/LoginForm.tsx (1)</summary>

`31-47`: **Well-implemented login submission flow with proper error handling.**

The submission handler properly validates CAPTCHA completion, processes form data, and handles success/error responses appropriately. The return URL handling is also well-implemented.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-05-02T13:28:22Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 2**

<details>
<summary>♻️ Duplicate comments (1)</summary><blockquote>

<details>
<summary>src/app/registration/page.tsx (1)</summary><blockquote>

`17-18`: _⚠️ Potential issue_

**Address the unresolved TODO for role handling**

The hardcoded role is still present. This should be addressed with proper role selection.



Consider implementing role selection as suggested in the previous review:
```diff
- //TODO handle role
- const testRole = 'Student';
+ // Replace hardcoded role with user-selectable input
+ const [selectedRole, setSelectedRole] = useState<'Student' | 'Teacher'>(
+   'Student'
+ );
```

And adding a role selector to the form that updates this state.

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (2)</summary><blockquote>

<details>
<summary>src/app/login/LoginForm.tsx (1)</summary><blockquote>

`54-56`: **Simplify boolean assignment**

The ternary operation can be simplified for better readability.

```diff
-	const handleCaptchaChange = (value: string | null) => {
-		setCaptchaCompleted(value ? true : false);
-	};
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(!!value);
+	};
```

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Biome (1.9.4)</summary>

[error] 55-55: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</blockquote></details>
<details>
<summary>src/app/registration/actions.ts (1)</summary><blockquote>

`15-19`: **Improve validation error feedback**

The current implementation only returns the first validation error message. For a better user experience, consider returning all validation errors.

```diff
if (!validationResult.success) {
	console.log(validationResult.error);
-	return { success: false, error: validationResult.error.message };
+	// Return formatted errors for all fields
+	return { 
+		success: false, 
+		errors: validationResult.error.format(),
+		error: validationResult.error.message 
+	};
}
```

This would allow the UI to display field-specific errors.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between cfca95f128cb72c3e37a5c02c3e5e546bbcad89e and 3fc8c3c0339897905f08ec299f4afe6d93074cf0.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `src/app/login/LoginForm.tsx` (1 hunks)
* `src/app/registration/actions.ts` (1 hunks)
* `src/app/registration/page.tsx` (5 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (3)</summary>

<details>
<summary>src/app/registration/page.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `RegistrationFormValues` (6-12)

</details>
<details>
<summary>src/app/registration/actions.ts (1)</summary>

* `createUser` (11-59)

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

* `registrationSchema` (3-19)

</details>

</blockquote></details>
<details>
<summary>src/app/registration/actions.ts (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `RegistrationFormValues` (6-12)

</details>
<details>
<summary>src/app/registration/validation.ts (1)</summary>

* `registrationSchema` (3-19)

</details>
<details>
<summary>firebase/clientApp.ts (2)</summary>

* `auth` (16-16)
* `db` (17-17)

</details>

</blockquote></details>
<details>
<summary>src/app/login/LoginForm.tsx (3)</summary><blockquote>

<details>
<summary>src/shared/Input/types.ts (1)</summary>

* `LoginFormValues` (1-4)

</details>
<details>
<summary>src/app/login/validation.ts (1)</summary>

* `loginSchema` (3-10)

</details>
<details>
<summary>src/app/login/utils.ts (2)</summary>

* `userLogin` (13-67)
* `LoginResult` (8-11)

</details>

</blockquote></details>

</details><details>
<summary>🪛 Biome (1.9.4)</summary>

<details>
<summary>src/app/login/LoginForm.tsx</summary>

[error] 55-55: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
 Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with


(lint/complexity/noUselessTernary)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (16)</summary><blockquote>

<details>
<summary>src/app/login/LoginForm.tsx (8)</summary>

`3-16`: **Well-structured import organization**

The imports are well-organized, separating React/Next.js dependencies, third-party libraries, local components, and assets/types. Good job using named imports for better code clarity.

---

`19-22`: **Clean state management for form concerns**

Good separation of concerns with distinct state variables for CAPTCHA status, password visibility, and login errors.

---

`24-30`: **Proper form configuration with type-safety**

The form setup correctly uses zodResolver with the imported schema and properly types the form values. This provides excellent type safety and validation.

---

`32-48`: **Well-implemented form submission handler**

The submission handler correctly:
1. Validates CAPTCHA completion
2. Handles the asynchronous login process
3. Manages redirects with return URL support
4. Properly handles and displays errors

This is a robust implementation.

---

`65-68`: **Improved validation error message**

The error message is now more clear about what the user needs to do, addressing the previous review comment about confusing validation error messaging.

---

`75-85`: **Correctly labeled email field**

The field is properly labeled as "Email" matching its purpose and placeholder, fixing the previous issue noted in earlier reviews.

---

`90-110`: **Well-implemented password visibility toggle**

The password visibility toggle is well-implemented with:
1. Dynamic type switching between text/password
2. Appropriate icon changes
3. Accessible button implementation with proper attributes

This improves user experience while maintaining security.

---

`120-127`: **Fixed sign-up navigation with Next.js Link**

The sign-up link now properly uses Next.js Link component for navigation, addressing the previous review comment about missing navigation functionality.

</details>
<details>
<summary>src/app/registration/page.tsx (5)</summary>

`2-16`: **Good integration of form validation libraries**

The imports now include React Hook Form with Zod validation, aligning with the login form implementation for a consistent approach to form handling throughout the application.

---

`22-36`: **Well-structured form submission with error handling**

The submission handler properly:
1. Uses async/await pattern
2. Manages error state
3. Navigates on success
4. Provides user feedback for failures

This is a significant improvement over the previous implementation.

---

`41-43`: **Proper form validation with Zod**

The form configuration now uses zodResolver with the imported schema, providing consistent validation across the application.

---

`70-74`: **Well-designed error message display**

The error message container has appropriate styling with:
1. Clear visual indication (red background and border)
2. Proper text formatting
3. Conditional rendering

This provides clear user feedback.

---

`105-114`: **Added password field with validation**

The password field is properly implemented with:
1. Correct input type
2. Required attribute
3. Error handling
4. Consistent styling with other fields

This addresses the previous review comment about missing password fields.

</details>
<details>
<summary>src/app/registration/actions.ts (3)</summary>

`1-10`: **Well-organized server action with proper imports**

The server action correctly:
1. Uses the 'use server' directive
2. Imports necessary Firebase and validation utilities
3. Follows a clean import structure

This establishes a good pattern for server-side actions.

---

`11-34`: **Comprehensive user creation implementation**

The user creation logic:
1. Validates input data through schema
2. Properly extracts validated data
3. Creates Firebase authentication user
4. Stores additional user data in Firestore
5. Returns appropriate success indicators

This addresses previous issues with hardcoded passwords by properly using the submitted password.

---

`35-58`: **Robust error handling for Firebase operations**

The error handling is comprehensive:
1. Distinguishes between Firebase and other errors
2. Provides specific user-friendly messages for different error codes
3. Logs detailed error information for debugging
4. Returns appropriate error information to the client

This is a significant improvement over the previous implementation noted in earlier reviews.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: CHANGES_REQUESTED
author_association: NONE
submitted_at: 2025-05-02T16:49:07Z

Review comments:
diff_hunk: @@ -1,18 +1,17 @@
 import { initializeApp } from 'firebase/app';
+import { getAuth } from 'firebase/auth';
 import { getFirestore } from 'firebase/firestore';
 
 const firebaseConfig = {
-	apiKey: process.env.FIREBASE_API_KEY,
-	authDomain: process.env.FIREBASE_AUTH_DOMAIN,
-	projectId: process.env.FIREBASE_PROJECT_ID,
-	storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
-	messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID,
-	appId: process.env.FIREBASE_APP_ID,
-	measurementId: process.env.FIREBASE_MEASUREMENT_ID,
+	apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
+	authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
+	projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
+	storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
+	messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
+	appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
+	measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
 };
path: firebase/clientApp.ts
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Good use of environment variables for configuration**

Using environment variables for Firebase configuration is a security best practice. Make sure these environment variables are properly documented in the project's README or `.env.example` file.


---

🏁 Script executed:

```shell
#!/bin/bash
# Check if there's an .env.example file that includes Firebase config variables
if [ -f .env.example ]; then
  echo "Checking .env.example for Firebase environment variables:"
  grep -E "NEXT_PUBLIC_FIREBASE_" .env.example || echo "Firebase environment variables not found in .env.example"
else
  echo ".env.example file not found. Consider creating one to document required environment variables."
fi

# Check if README mentions Firebase environment setup
if [ -f README.md ]; then
  echo "Checking README.md for Firebase environment variables documentation:"
  grep -E -A 5 -B 5 "NEXT_PUBLIC_FIREBASE_|environment|.env" README.md || echo "Firebase environment setup not documented in README.md"
else
  echo "README.md file not found."
fi
```

Length of output: 584

---



</details>

**Document Firebase Environment Variables**

The Firebase configuration variables aren’t documented in your project. Please add them to a `.env.example` file and update the README with setup instructions.

• Create a root-level `.env.example` including:
```
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=
```  
• In `README.md`, add a section like:
```
## Environment Variables

Create a `.env.local` file in the project root:

```
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_auth_domain
…
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=your_measurement_id
```
```  
This ensures new developers know which variables to set before running the app.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:44Z
author_association: NONE
diff_hunk: @@ -1,9 +1,16 @@
-export interface IFormValues {
+export type LoginFormValues = {
 	username: string;
 	password: string;
+};
path: src/shared/Input/types.ts
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Clearly defined login form type.**

The separation of form types improves type safety throughout the application.



Note that you're using `username` for login, but Firebase Authentication typically uses email-based authentication. Verify that this is intentional and consistent with your authentication implementation:

---

🏁 Script executed:

```shell
#!/bin/bash
# Check if Firebase auth is using email or username in the codebase
rg -A 3 "signInWith(Email|Password)" --glob "*.{ts,tsx,js,jsx}"
```

Length of output: 546

---



</details>

**Align form field with Firebase Auth’s expectations**

You’ve defined `LoginFormValues` with `username` and `password`, which is clear—but since you’re calling  
```ts
await signInWithEmailAndPassword(auth, username, password);
```  
the `username` field is actually treated as an email. To improve clarity and consistency, rename `username` to `email` across your codebase:

- **src/shared/Input/types.ts**:  
  • Change `username: string` → `email: string`  
- **src/app/login/utils.ts**:  
  • Destructure `{ email, password }` instead of `{ username, password }`  
  • Call `signInWithEmailAndPassword(auth, email, password)`  
- **Form components & validation**:  
  • Update any inputs, schemas, and labels referring to `username`

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:44Z
author_association: NONE
diff_hunk: @@ -1,30 +1,29 @@
 'use client';
 import React from 'react';
-import { useForm, SubmitHandler } from 'react-hook-form';
-import { IFormValues } from '@/shared/Input/types';
+import { useForm } from 'react-hook-form';
+import { RegistrationFormValues } from '@/shared/Input/types';
 import Image from 'next/image';
 import Input from '@/shared/Input/Input';
 import Selector from '@/shared/Selector/Selector';
 import Button from '@/shared/Button/Button';
-
 import { regTrainee, regStudent } from '@/assets';
 import { specializations } from '@/constants/Registration/constants';
 
+import { createUser } from './actions';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { registrationSchema } from './validation';
+
+//TODO handle role
 const testRole = 'Student';
path: src/app/registration/page.tsx
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Unresolved TODO for role handling.**

The current implementation uses a hardcoded `testRole` value.


Implement proper role handling to replace the TODO comment. Consider adding a role selector in the form or determining the role based on the user's registration path.

---

🏁 Script executed:

```shell
#!/bin/bash
# Check if there are other role-related TODOs in the codebase
rg "TODO.*role" --glob "*.{ts,tsx,js,jsx}"
```

Length of output: 93

---



</details>

**Address the unresolved `TODO` for dynamic role handling**

The hardcoded `testRole = 'Student'` is still present in `src/app/registration/page.tsx` (lines 16–17). You’ll need to replace it with real role selection logic:

• File: `src/app/registration/page.tsx`  
  Lines: 16–17  

Suggested diff:
```diff
- //TODO handle role
- const testRole = 'Student';
+ // Replace hardcoded role with user-selectable input
+ const [selectedRole, setSelectedRole] = useState<'Student' | 'Teacher'>(/* default value */);
+
+ // In the registration form JSX:
+ <label htmlFor="role">Role</label>
+ <select
+   id="role"
+   name="role"
+   value={selectedRole}
+   onChange={(e) => setSelectedRole(e.target.value as 'Student' | 'Teacher')}
+ >
+   <option value="Student">Student</option>
+   <option value="Teacher">Teacher</option>
+   {/* add other roles here */}
+ </select>
```
Then pass `selectedRole` into your registration handler/API so the backend receives the correct role.  


> Committable suggestion skipped: line range outside the PR's diff.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -49,9 +48,9 @@ const Registration = () => {
 					/>
 					<form
 						className='flex flex-col gap-6 w-[629px] min-h-fit'
-						onSubmit={handleSubmit(onSubmit)}
+						onSubmit={handleSubmit(createUser)}
 					>
path: src/app/registration/page.tsx
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Form submission directly calls createUser action.**

This is a clean approach that separates form handling from business logic.


However, there is no password field in the form while the `createUser` function in `actions.ts` uses a hardcoded password, which is a security issue. Add password fields to the form:

```diff
<form
    className='flex flex-col gap-6 w-[629px] min-h-fit'
    onSubmit={handleSubmit(createUser)}
>
    {/* Existing fields */}
+   <Input<RegistrationFormValues>
+       register={register}
+       label='Password'
+       type='password'
+       name='password'
+       placeholder='Enter password'
+       required
+       variant='transparent'
+       error={errors.password}
+   />
+   <Input<RegistrationFormValues>
+       register={register}
+       label='Confirm Password'
+       type='password'
+       name='confirmPassword'
+       placeholder='Confirm password'
+       required
+       variant='transparent'
+       error={errors.confirmPassword}
+   />
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
					<form
						className='flex flex-col gap-6 w-[629px] min-h-fit'
						onSubmit={handleSubmit(createUser)}
					>
						{/* Existing fields */}
						<Input<RegistrationFormValues>
							register={register}
							label='Password'
							type='password'
							name='password'
							placeholder='Enter password'
							required
							variant='transparent'
							error={errors.password}
						/>
						<Input<RegistrationFormValues>
							register={register}
							label='Confirm Password'
							type='password'
							name='confirmPassword'
							placeholder='Confirm password'
							required
							variant='transparent'
							error={errors.confirmPassword}
						/>
					</form>
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,41 @@
+'use server';
+import { SubmitHandler } from 'react-hook-form';
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { auth, db } from '../../../firebase/clientApp';
+import { doc, setDoc } from 'firebase/firestore';
+
+import { RegistrationFormValues } from '@/shared/Input/types';
+import { registrationSchema } from './validation';
+
+export const createUser: SubmitHandler<RegistrationFormValues> = async (
+	data
+) => {
+	try {
+		const validationResult = registrationSchema.safeParse(data);
+		if (!validationResult.success) {
+			console.log(validationResult.error);
+			return;
+		}
+		const { firstName, lastName, email, specialization } =
+			validationResult.data;
+		//TODO handle password
+		const userCredential = await createUserWithEmailAndPassword(
+			auth,
+			email,
+			'data.password'
+		);
path: src/app/registration/actions.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Fix the hardcoded password issue**

The function is currently using a hardcoded string `'data.password'` instead of an actual password from the form data. This is a security concern and doesn't reflect actual user input.


Update the implementation to either:
1. Accept a password field in the form data and validation schema, or
2. Implement a secure password generation mechanism with email notification for account setup

```diff
- const userCredential = await createUserWithEmailAndPassword(
-   auth,
-   email,
-   'data.password'
- );
+ // Option 1: Use password from form data
+ const userCredential = await createUserWithEmailAndPassword(
+   auth,
+   email,
+   data.password
+ );
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
		// Option 1: Use password from form data
		const userCredential = await createUserWithEmailAndPassword(
			auth,
			email,
			data.password
		);
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commits 925fc6b to cfca95f
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,41 @@
+'use server';
+import { SubmitHandler } from 'react-hook-form';
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { auth, db } from '../../../firebase/clientApp';
+import { doc, setDoc } from 'firebase/firestore';
+
+import { RegistrationFormValues } from '@/shared/Input/types';
+import { registrationSchema } from './validation';
+
+export const createUser: SubmitHandler<RegistrationFormValues> = async (
+	data
+) => {
+	try {
+		const validationResult = registrationSchema.safeParse(data);
+		if (!validationResult.success) {
+			console.log(validationResult.error);
+			return;
+		}
path: src/app/registration/actions.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Improve validation error handling**

Currently, validation errors are only logged to the console and not returned to the client. This prevents proper error feedback to users.


Return validation errors to provide meaningful feedback:

```diff
if (!validationResult.success) {
  console.log(validationResult.error);
- return;
+ return { success: false, error: validationResult.error.format() };
}
```

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commits 2fa2174 to 3fc8c3c
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,41 @@
+'use server';
+import { SubmitHandler } from 'react-hook-form';
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { auth, db } from '../../../firebase/clientApp';
+import { doc, setDoc } from 'firebase/firestore';
+
+import { RegistrationFormValues } from '@/shared/Input/types';
+import { registrationSchema } from './validation';
+
+export const createUser: SubmitHandler<RegistrationFormValues> = async (
+	data
+) => {
+	try {
+		const validationResult = registrationSchema.safeParse(data);
+		if (!validationResult.success) {
+			console.log(validationResult.error);
+			return;
+		}
+		const { firstName, lastName, email, specialization } =
+			validationResult.data;
+		//TODO handle password
+		const userCredential = await createUserWithEmailAndPassword(
+			auth,
+			email,
+			'data.password'
+		);
+		const uid = userCredential.user.uid;
+		const userProfile = {
+			uid,
+			firstName: firstName,
+			lastName: lastName,
+			email: email,
+			specialization: specialization,
+			role: 'student',
+		};
+		await setDoc(doc(db, 'users', uid), userProfile);
+	} catch (e) {
+		//TODO handle error
+		console.error('An error occured', e);
+	}
path: src/app/registration/actions.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Implement proper error handling**

The error handling is incomplete as noted by the TODO comment. Only logging errors to the console isn't sufficient for production code.


Implement proper error handling that provides meaningful feedback:

```diff
catch (e) {
- //TODO handle error
- console.error('An error occured', e);
+ let errorMessage = 'An error occurred during registration';
+ 
+ if (e instanceof FirebaseError) {
+   // Handle specific Firebase errors
+   switch (e.code) {
+     case 'auth/email-already-in-use':
+       errorMessage = 'This email is already registered';
+       break;
+     case 'auth/invalid-email':
+       errorMessage = 'Invalid email format';
+       break;
+     // Add other specific cases as needed
+   }
+ }
+ 
+ console.error(errorMessage, e);
+ return { success: false, error: errorMessage };
}
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
	} catch (e) {
		let errorMessage = 'An error occurred during registration';

		if (e instanceof FirebaseError) {
			// Handle specific Firebase errors
			switch (e.code) {
				case 'auth/email-already-in-use':
					errorMessage = 'This email is already registered';
					break;
				case 'auth/invalid-email':
					errorMessage = 'Invalid email format';
					break;
				// Add other specific cases as needed
			}
		}

		console.error(errorMessage, e);
		return { success: false, error: errorMessage };
	}
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,67 @@
+import { signInWithEmailAndPassword } from 'firebase/auth';
+import { FirebaseError } from 'firebase/app';
+import { auth } from '@/../firebase/clientApp';
+import { loginSchema } from './validation';
+import { SubmitHandler } from 'react-hook-form';
+import { LoginFormValues } from '@/shared/Input/types';
+
+export type LoginResult = {
+	success: boolean;
+	error?: string;
+};
+
+export const userLogin: SubmitHandler<LoginFormValues> = async (
+	data
+): Promise<LoginResult> => {
+	try {
+		const validationResult = loginSchema.safeParse(data);
+		if (!validationResult.success) {
+			return {
+				success: false,
+				error: 'Invalid form data',
+			};
+		}
+
+		const { username, password } = validationResult.data;
+		await signInWithEmailAndPassword(auth, username, password);
+		return {
+			success: true,
+		};
+	} catch (error) {
+		if (error instanceof FirebaseError) {
+			console.log(error.code);
+			switch (error.code) {
+				case 'auth/too-many-requests':
+					return {
+						success: false,
+						error: 'Too many attempts. Try again later',
+					};
+				case 'auth/invalid-email':
+					return {
+						success: false,
+						error: 'Invalid email format',
+					};
+				case 'auth/user-disabled':
+					return {
+						success: false,
+						error: 'This account has been disabled',
+					};
+				case 'auth/invalid-credential':
+					return {
+						success: false,
+						error: 'Invalid email or password',
+					};
+				default:
+					return {
+						success: false,
+						error: 'An error occurred during login',
+					};
+			}
+		}
+
+		return {
+			success: false,
+			error: 'An unexpected error occurred',
+		};
+	}
+};
path: src/app/login/utils.ts
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Verify correct handling of email fields**

The login function uses `username` as the form field, but the Firebase function expects an email address. This might lead to confusion for users.


Check that the username field is consistently treated as an email address throughout the application. Consider renaming for clarity:

---

🏁 Script executed:

```shell
#!/bin/bash
# Check for username vs email field terminology
rg -i "username|email" --type ts --type tsx --glob "!node_modules/" --glob "!.git/"
```

Length of output: 113

---

I've adjusted the search to target `.ts`/`.tsx` files without relying on unsupported `--type` flags. Let’s rerun:

---

🏁 Script executed:

```shell
#!/bin/bash
# Search for occurrences of "username" and "email" in TS/TSX files
rg -in "username" --glob "*.ts" --glob "*.tsx" --glob "!node_modules/*" --glob "!.git/*"
rg -in "email"    --glob "*.ts" --glob "*.tsx" --glob "!node_modules/*" --glob "!.git/*"
```

Length of output: 2707

---



</details>

**Rename “username” to “email” in the login flow for consistency**

The login feature currently treats `username` as an email (validated via `z.string().email()` and using an “Enter email” placeholder), while the registration flow uses `email` throughout. This inconsistency can confuse both developers and users. Please update the login flow to use `email` everywhere:

• src/app/login/validation.ts  
  – Rename the schema key from `username` to `email`  
  – Update its error message to “Email must be a valid email address”  

• src/app/login/LoginForm.tsx  
  – Change `name`, `id`, and label from `username` to `email`  
  – Update placeholder, error checks (`errors.email`), and validation messages  

• src/app/login/utils.ts  
  – Destructure `{ email, password }` instead of `{ username, password }`  
  – Call `signInWithEmailAndPassword(auth, email, password)`  

• src/types.ts & src/shared/Input/types.ts  
  – Review the `username: string` definitions; remove or alias them if they’re only used to capture an email in login  

After making these changes, run a quick search under `src/app/login` to catch any remaining `username` references and update them to `email`.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,45 @@
+import { NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+
+const publicPaths = [
+	'/',
+	'/join-us',
+	'/blog',
+	'/pricing',
+	'/about',
+	'/login',
+	'/registration',
+];
+
+const isPublicPath = (path: string) => {
+	return publicPaths.some((publicPath) => {
+		if (publicPath === path) return true;
+		return path.startsWith(`${publicPath}/`);
+	});
+};
+
+export async function middleware(request: NextRequest) {
+	const { pathname } = request.nextUrl;
+
+	if (
+		isPublicPath(pathname) ||
+		pathname.startsWith('/_next/') ||
+		pathname.includes('.')
+	) {
+		return NextResponse.next();
+	}
+
+	const authCookie = request.cookies.get('firebase-auth-token')?.value;
path: src/middleware.ts
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Extract cookie name to a constant**

The cookie name 'firebase-auth-token' is hardcoded in this file, which could lead to inconsistencies if the name changes.


Use a constant from a central location:

```diff
- const authCookie = request.cookies.get('firebase-auth-token')?.value;
+ import { COOKIE_NAME } from '@/constants/constants';
+ const authCookie = request.cookies.get(COOKIE_NAME)?.value;
```


> Committable suggestion skipped: line range outside the PR's diff.

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 37e9279
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,45 @@
+import { NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+
+const publicPaths = [
+	'/',
+	'/join-us',
+	'/blog',
+	'/pricing',
+	'/about',
+	'/login',
+	'/registration',
+];
+
+const isPublicPath = (path: string) => {
+	return publicPaths.some((publicPath) => {
+		if (publicPath === path) return true;
+		return path.startsWith(`${publicPath}/`);
+	});
+};
+
+export async function middleware(request: NextRequest) {
+	const { pathname } = request.nextUrl;
+
+	if (
+		isPublicPath(pathname) ||
+		pathname.startsWith('/_next/') ||
+		pathname.includes('.')
+	) {
+		return NextResponse.next();
+	}
path: src/middleware.ts
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Verify handling of file paths with dots in the middle**

The current check for static files uses `pathname.includes('.')` which might incorrectly match paths that have dots in the middle but aren't actually static files.

---

🏁 Script executed:

```shell
#!/bin/bash
# Check for potential path issues with dots
echo "Testing paths with dots that aren't files:"
echo "Path: /user.profile/settings - Would be treated as: static file (bypassing auth)"
echo "Path: /api/v1.0/users - Would be treated as: static file (bypassing auth)"
echo "This could potentially allow unauthorized access to certain routes."
```

Length of output: 570

---



</details>

**Refine static‐file check to avoid bypassing auth for routes with dots**  
  
The use of `pathname.includes('.')` treats *any* path containing a dot as a static asset—e.g. `/user.profile/settings` or `/api/v1.0/users`—and skips your auth middleware. Instead, restrict to real file extensions at the end of the URL. For example:

```ts
// Match only “.ext” at end of path
const hasFileExtension = /\.\w+$/;

if (
  isPublicPath(pathname) ||
  pathname.startsWith('/_next/') ||
  hasFileExtension.test(pathname)
) {
  return NextResponse.next();
}
```

Or explicitly list common extensions:

```ts
const staticExt = /\.(css|js|png|jpg|jpeg|svg|ico|json|woff2?|eot|ttf)$/;

if (
  isPublicPath(pathname) ||
  pathname.startsWith('/_next/') ||
  staticExt.test(pathname)
) {
  return NextResponse.next();
}
```

• Verify that routes like `/user.profile/settings` and `/api/v1.0/users` no longer bypass authentication.  
• Consider adding unit tests for both valid static‐file URLs and dotted‐route URLs.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,143 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { SubmitHandler, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import Image from 'next/image';
+import ReCAPTCHA from 'react-google-recaptcha';
+import Input from '@/shared/Input/Input';
+import Button from '@/shared/Button/Button';
+
+import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { LoginFormValues } from '@/shared/Input/types';
+import { loginSchema } from './validation';
+import { userLogin, LoginResult } from './utils';
+
+const Login = () => {
+	const [captchaCompleted, setCaptchaCompleted] = useState(false);
+	const [captchaWarning, setCaptchaWarning] = useState(false);
+	const [isPasswordVisible, setPasswordVisible] = useState(false);
+	const [loginError, setLoginError] = useState<string | null>(null);
+
+	const router = useRouter();
+	const searchParams = useSearchParams();
+	const {
+		register,
+		formState: { errors, isSubmitting },
+		handleSubmit,
+	} = useForm<LoginFormValues>({ resolver: zodResolver(loginSchema) });
+
+	const onSubmit: SubmitHandler<LoginFormValues> = async (data) => {
+		if (!captchaCompleted) {
+			setCaptchaWarning(true);
+			return;
+		}
+		if (!data) return;
+
+		setLoginError(null);
+		const res: LoginResult = await userLogin(data);
+
+		if (res.success) {
+			const returnUrl = searchParams.get('returnUrl') || '/';
+			router.push(returnUrl);
+		} else if (res.error) {
+			setLoginError(res.error);
+		}
+	};
+
+	const handleToggle = () => {
+		setPasswordVisible(!isPasswordVisible);
+	};
+
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(value ? true : false);
+	};
+
+	return (
+		<div className='min-h-screen flex items-center justify-center pb-32'>
+			<div className='flex flex-col items-center gap-5'>
+				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
+					Sign in
+				</p>
+				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
+				{(errors.username || errors.password) && (
+					<p className='text-red-600 font-poppins font-semibold inline-block'>
+						You're entered either wrong username or password
+					</p>
+				)}
+				<form
+					className='flex flex-col items-center gap-4'
+					onSubmit={handleSubmit(onSubmit)}
+				>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>
+							User name
+						</label>
+						<Input<LoginFormValues>
+							icon={userIcon}
+							register={register}
+							name='username'
+							type='text'
+							id='username'
+							placeholder='Enter email'
+							variant='withIcon'
+						/>
+					</div>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>
+							Password
+						</label>
+						<Input<LoginFormValues>
+							icon={padlockIcon}
+							register={register}
+							name='password'
+							type={isPasswordVisible ? 'text' : 'password'}
+							id='password'
+							placeholder='Enter password'
+							variant='withIcon'
+						>
+							<div className='absolute right-3 top-3'>
+								<button type='button' onClick={handleToggle}>
+									<Image
+										src={isPasswordVisible ? eyeOn.src : eyeOff.src}
+										className='w-4'
+										alt='Toggle visibility'
+										width={16}
+										height={16}
+									/>
+								</button>
+							</div>
+						</Input>
+					</div>
+
+					<Button
+						message='Sign in'
+						size='large'
+						disabled={isSubmitting}
+						variant='primeButton'
+					/>
+					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
+					<p className='text-sm text-neutral-500 font-poppins'>
+						Don&apos;t have an account?{' '}
+						<span className='text-indigo-700 font-bold cursor-pointer'>
+							Sign up
+						</span>
+					</p>
path: src/app/login/LoginForm.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Add navigation to the Sign up link**

The "Sign up" text is styled as a clickable element but doesn't have any navigation functionality. Consider adding a link to the registration page.


```diff
-	<p className='text-sm text-neutral-500 font-poppins'>
-		Don&apos;t have an account?{' '}
-		<span className='text-indigo-700 font-bold cursor-pointer'>
-			Sign up
-		</span>
-	</p>
+	<p className='text-sm text-neutral-500 font-poppins'>
+		Don&apos;t have an account?{' '}
+		<span 
+			className='text-indigo-700 font-bold cursor-pointer'
+			onClick={() => router.push('/registration')}
+		>
+			Sign up
+		</span>
+	</p>
```

Or, better yet, use Next.js Link component:

```diff
+import Link from 'next/link';

...

-	<p className='text-sm text-neutral-500 font-poppins'>
-		Don&apos;t have an account?{' '}
-		<span className='text-indigo-700 font-bold cursor-pointer'>
-			Sign up
-		</span>
-	</p>
+	<p className='text-sm text-neutral-500 font-poppins'>
+		Don&apos;t have an account?{' '}
+		<Link href="/registration" className='text-indigo-700 font-bold'>
+			Sign up
+		</Link>
+	</p>
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
import Link from 'next/link';

					<p className='text-sm text-neutral-500 font-poppins'>
						Don&apos;t have an account?{' '}
						<Link href="/registration" className='text-indigo-700 font-bold'>
							Sign up
						</Link>
					</p>
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T12:57:45Z
author_association: NONE
diff_hunk: @@ -0,0 +1,143 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { SubmitHandler, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import Image from 'next/image';
+import ReCAPTCHA from 'react-google-recaptcha';
+import Input from '@/shared/Input/Input';
+import Button from '@/shared/Button/Button';
+
+import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { LoginFormValues } from '@/shared/Input/types';
+import { loginSchema } from './validation';
+import { userLogin, LoginResult } from './utils';
+
+const Login = () => {
+	const [captchaCompleted, setCaptchaCompleted] = useState(false);
+	const [captchaWarning, setCaptchaWarning] = useState(false);
+	const [isPasswordVisible, setPasswordVisible] = useState(false);
+	const [loginError, setLoginError] = useState<string | null>(null);
+
+	const router = useRouter();
+	const searchParams = useSearchParams();
+	const {
+		register,
+		formState: { errors, isSubmitting },
+		handleSubmit,
+	} = useForm<LoginFormValues>({ resolver: zodResolver(loginSchema) });
+
+	const onSubmit: SubmitHandler<LoginFormValues> = async (data) => {
+		if (!captchaCompleted) {
+			setCaptchaWarning(true);
+			return;
+		}
+		if (!data) return;
+
+		setLoginError(null);
+		const res = (await userLogin(data)) as LoginResult;
+
+		if (res.success) {
+			const returnUrl = searchParams.get('returnUrl') || '/';
+			router.push(returnUrl);
+		} else if (res.error) {
+			setLoginError(res.error);
+		}
+	};
+
+	const handleToggle = () => {
+		setPasswordVisible(!isPasswordVisible);
+	};
+
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(value ? true : false);
+	};
+
+	return (
+		<div className='min-h-screen flex items-center justify-center pb-32'>
+			<div className='flex flex-col items-center gap-5'>
+				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
+					Sign in
+				</p>
+				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
+				{(errors.username || errors.password) && (
+					<p className='text-red-600 font-poppins font-semibold inline-block'>
+						You're entered either wrong username or password
+					</p>
+				)}
path: src/app/login/LoginForm.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Clarify validation error message**

The current error message suggests authentication failure ("wrong username or password"), but it's actually shown for form validation issues before submission. This can confuse users.


```diff
{(errors.username || errors.password) && (
  <p className='text-red-600 font-poppins font-semibold inline-block'>
-    You're entered either wrong username or password
+    Please enter a valid username and password
  </p>
)}
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
				{(errors.username || errors.password) && (
					<p className='text-red-600 font-poppins font-semibold inline-block'>
						Please enter a valid username and password
					</p>
				)}
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T13:10:07Z
author_association: NONE
diff_hunk: @@ -0,0 +1,143 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { SubmitHandler, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import Image from 'next/image';
+import ReCAPTCHA from 'react-google-recaptcha';
+import Input from '@/shared/Input/Input';
+import Button from '@/shared/Button/Button';
+
+import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { LoginFormValues } from '@/shared/Input/types';
+import { loginSchema } from './validation';
+import { userLogin, LoginResult } from './utils';
+
+const Login = () => {
+	const [captchaCompleted, setCaptchaCompleted] = useState(false);
+	const [captchaWarning, setCaptchaWarning] = useState(false);
+	const [isPasswordVisible, setPasswordVisible] = useState(false);
+	const [loginError, setLoginError] = useState<string | null>(null);
+
+	const router = useRouter();
+	const searchParams = useSearchParams();
+	const {
+		register,
+		formState: { errors, isSubmitting },
+		handleSubmit,
+	} = useForm<LoginFormValues>({ resolver: zodResolver(loginSchema) });
+
+	const onSubmit: SubmitHandler<LoginFormValues> = async (data) => {
+		if (!captchaCompleted) {
+			setCaptchaWarning(true);
+			return;
+		}
+		if (!data) return;
+
+		setLoginError(null);
+		const res = (await userLogin(data)) as LoginResult;
+
+		if (res.success) {
+			const returnUrl = searchParams.get('returnUrl') || '/';
+			router.push(returnUrl);
+		} else if (res.error) {
+			setLoginError(res.error);
+		}
+	};
+
+	const handleToggle = () => {
+		setPasswordVisible(!isPasswordVisible);
+	};
+
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(value ? true : false);
+	};
+
+	return (
+		<div className='min-h-screen flex items-center justify-center pb-32'>
+			<div className='flex flex-col items-center gap-5'>
+				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
+					Sign in
+				</p>
+				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
+				{(errors.email || errors.password) && (
+					<p className='text-red-600 font-poppins font-semibold inline-block'>
+						You're entered either wrong username or password
+					</p>
+				)}
+				<form
+					className='flex flex-col items-center gap-4'
+					onSubmit={handleSubmit(onSubmit)}
+				>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>
+							User name
+						</label>
path: src/app/login/LoginForm.tsx
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Update label to match field content.**

The label "User name" doesn't match the field's actual purpose, which is for email input. This mismatch could confuse users.


```diff
-						<label className='text-sm font-semibold font-poppins'>
-							User name
-						</label>
+						<label className='text-sm font-semibold font-poppins'>
+							Email
+						</label>
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
                        <label className='text-sm font-semibold font-poppins'>
                            Email
                        </label>
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commits 2fa2174 to 3fc8c3c
created_at: 2025-05-02T13:28:20Z
author_association: NONE
diff_hunk: @@ -0,0 +1,144 @@
+'use client';
+
+import React, { useState } from 'react';
+import { useRouter, useSearchParams } from 'next/navigation';
+import { SubmitHandler, useForm } from 'react-hook-form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import Image from 'next/image';
+import ReCAPTCHA from 'react-google-recaptcha';
+import Input from '@/shared/Input/Input';
+import Button from '@/shared/Button/Button';
+
+import { userIcon, padlockIcon, eyeOn, eyeOff } from '../../assets/index';
+import { LoginFormValues } from '@/shared/Input/types';
+import { loginSchema } from './validation';
+import { userLogin, LoginResult } from './utils';
+import Link from 'next/link';
+
+const Login = () => {
+	const [captchaCompleted, setCaptchaCompleted] = useState(false);
+	const [captchaWarning, setCaptchaWarning] = useState(false);
+	const [isPasswordVisible, setPasswordVisible] = useState(false);
+	const [loginError, setLoginError] = useState<string | null>(null);
+
+	const router = useRouter();
+	const searchParams = useSearchParams();
+	const {
+		register,
+		formState: { errors, isSubmitting },
+		handleSubmit,
+	} = useForm<LoginFormValues>({ resolver: zodResolver(loginSchema) });
+
+	const onSubmit: SubmitHandler<LoginFormValues> = async (data) => {
+		if (!captchaCompleted) {
+			setCaptchaWarning(true);
+			return;
+		}
+		if (!data) return;
+
+		setLoginError(null);
+		const res = (await userLogin(data)) as LoginResult;
+
+		if (res.success) {
+			const returnUrl = searchParams.get('returnUrl') || '/';
+			router.push(returnUrl);
+		} else if (res.error) {
+			setLoginError(res.error);
+		}
+	};
+
+	const handleToggle = () => {
+		setPasswordVisible(!isPasswordVisible);
+	};
+
+	const handleCaptchaChange = (value: string | null) => {
+		setCaptchaCompleted(value ? true : false);
+	};
+
+	return (
+		<div className='min-h-screen flex items-center justify-center pb-32'>
+			<div className='flex flex-col items-center gap-5'>
+				<p className='text-3xl text-neutral-900 font-montserrat font-semibold'>
+					Sign in
+				</p>
+				<p className='text-xl text-neutral-500 font-montserrat'>Welcome back</p>
+				{(errors.email || errors.password) && (
+					<p className='text-red-600 font-poppins font-semibold inline-block'>
+						Please enter a valid email and password
+					</p>
+				)}
+				<form
+					className='flex flex-col items-center gap-4'
+					onSubmit={handleSubmit(onSubmit)}
+				>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>Email</label>
+						<Input<LoginFormValues>
+							icon={userIcon}
+							register={register}
+							name='email'
+							type='text'
+							id='email'
+							placeholder='Enter email'
+							variant='withIcon'
+						/>
+					</div>
+					<div className='flex flex-col'>
+						<label className='text-sm font-semibold font-poppins'>
+							Password
+						</label>
+						<Input<LoginFormValues>
+							icon={padlockIcon}
+							register={register}
+							name='password'
+							type={isPasswordVisible ? 'text' : 'password'}
+							id='password'
+							placeholder='Enter password'
+							variant='withIcon'
+						>
+							<div className='absolute right-3 top-3'>
+								<button type='button' onClick={handleToggle}>
+									<Image
+										src={isPasswordVisible ? eyeOn.src : eyeOff.src}
+										className='w-4'
+										alt='Toggle visibility'
+										width={16}
+										height={16}
+									/>
+								</button>
+							</div>
+						</Input>
+					</div>
+
+					<Button
+						message='Sign in'
+						size='large'
+						disabled={isSubmitting}
+						variant='primeButton'
+					/>
+					<p className='text-xs text-neutral-500 font-poppins font-bold'>OR</p>
+					<Link href='/join-us'>
+						<p className='text-sm text-neutral-500 font-poppins'>
+							Don&apos;t have an account?{' '}
+							<span className='text-indigo-700 font-bold cursor-pointer'>
+								Sign up
+							</span>
+						</p>
+					</Link>
+					{captchaWarning && (
+						<p className='text-sm text-red-500'>Please complete the captcha</p>
+					)}
+					{loginError && (
+						<p className='text-sm text-red-500 mt-2'>{loginError}</p>
+					)}
+					<ReCAPTCHA
+						sitekey={process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY as string}
+						onChange={handleCaptchaChange}
+					/>
path: src/app/login/LoginForm.tsx
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>❓ Verification inconclusive</summary>

**Verify reCAPTCHA site key availability**

Ensure that the NEXT_PUBLIC_RECAPTCHA_SITE_KEY environment variable is properly configured in all environments where the application will be deployed.

---

🏁 Script executed:

```shell
#!/bin/bash
# Check if the RECAPTCHA environment variable is mentioned in documentation
grep -r "NEXT_PUBLIC_RECAPTCHA_SITE_KEY" --include="*.md" .

# Check if there are example env files that include this variable
grep -r "NEXT_PUBLIC_RECAPTCHA_SITE_KEY" --include=".env*" .
```

Length of output: 120

---



</details>

**Add reCAPTCHA site key to documentation and sample .env**

We didn’t find any mentions of `NEXT_PUBLIC_RECAPTCHA_SITE_KEY` in your Markdown docs or example .env files. Please:

- Add `NEXT_PUBLIC_RECAPTCHA_SITE_KEY` (with a placeholder value) to your `.env.example` or similar sample file.  
- Document it in your README or deployment guide, noting which environments require it.  
- Verify that your staging, CI/CD, and production systems all define this variable before enabling the ReCAPTCHA component.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T16:49:06Z
author_association: NONE
diff_hunk: @@ -0,0 +1,59 @@
+'use server';
+import { SubmitHandler } from 'react-hook-form';
+import { FirebaseError } from 'firebase/app';
+import { createUserWithEmailAndPassword } from 'firebase/auth';
+import { auth, db } from '../../../firebase/clientApp';
+import { doc, setDoc } from 'firebase/firestore';
+
+import { RegistrationFormValues } from '@/shared/Input/types';
+import { registrationSchema } from './validation';
+
+export const createUser: SubmitHandler<RegistrationFormValues> = async (
+	data
+) => {
+	try {
+		const validationResult = registrationSchema.safeParse(data);
+		if (!validationResult.success) {
+			console.log(validationResult.error);
+			return { success: false, error: validationResult.error.message };
+		}
+		const { firstName, lastName, email, specialization, password } =
+			validationResult.data;
+		const res = await createUserWithEmailAndPassword(auth, email, password);
+		const uid = res.user.uid;
+		const userProfile = {
+			uid,
+			firstName: firstName,
+			lastName: lastName,
+			email: email,
+			specialization: specialization,
+			role: 'student',
+		};
path: src/app/registration/actions.ts
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Hardcoded user role**

The role is hardcoded as 'student' regardless of the selected specialization or any other input.


Consider one of these approaches:
1. Pass the role from the registration form
2. Determine role based on other form inputs or registration context

```diff
const userProfile = {
	uid,
	firstName: firstName,
	lastName: lastName,
	email: email,
	specialization: specialization,
-	role: 'student',
+	role: data.role || 'student', // Add role to RegistrationFormValues type
};
```

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-05-02T16:49:06Z
author_association: NONE

PR comments:
user: login: vercel[bot]
created_at: 2025-05-02T12:54:42Z
body: [vc]: #9v8t5xZ7S5X34GdV7OQDhc/ryddZJs1vwv0WshliuMg=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJsZWFybi1hcHAiLCJsaXZlRmVlZGJhY2siOnsicmVzb2x2ZWQiOjAsInVucmVzb2x2ZWQiOjAsInRvdGFsIjowLCJsaW5rIjoibGVhcm4tYXBwLWdpdC01LWltcGxlbWVudC1sb2dpbi1hdXRoZS1lM2JmMTYtdGFtYWRla2tzLXByb2plY3RzLnZlcmNlbC5hcHAifSwiaW5zcGVjdG9yVXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL3RhbWFkZWtrcy1wcm9qZWN0cy9sZWFybi1hcHAvNWY2c3VmeEY2QmJMNkxIUThvQ0FmemVSMXBUOSIsInByZXZpZXdVcmwiOiJsZWFybi1hcHAtZ2l0LTUtaW1wbGVtZW50LWxvZ2luLWF1dGhlLWUzYmYxNi10YW1hZGVra3MtcHJvamVjdHMudmVyY2VsLmFwcCIsIm5leHRDb21taXRTdGF0dXMiOiJERVBMT1lFRCIsInJvb3REaXJlY3RvcnkiOm51bGx9XX0=
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Comments | Updated (UTC) |
| :--- | :----- | :------ | :------- | :------ |
| **learn-app** | ✅ Ready ([Inspect](https://vercel.com/tamadekks-projects/learn-app/5f6sufxF6BbL6LHQ8oCAfzeR1pT9)) | [Visit Preview](https://learn-app-git-5-implement-login-authe-e3bf16-tamadekks-projects.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/learn-app-git-5-implement-login-authe-e3bf16-tamadekks-projects.vercel.app?via=pr-comment-feedback-link) | May 2, 2025 4:52pm |


author_association: NONE
user: login: coderabbitai[bot]
created_at: 2025-05-02T12:54:45Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

"""
## Walkthrough

This update introduces a comprehensive authentication and form validation system across the application. It adds new context providers, middleware for route protection, and utilities for managing authentication state and cookies. Form handling for login and registration now leverages `react-hook-form` with `zod` schema validation, and related types have been refactored for improved type safety and flexibility. Firebase integration is updated to use environment variables and named exports. Several new dependencies are added, and constants for authentication tokens are introduced. The codebase now enforces authentication on protected routes and centralizes validation logic for user input.

## Changes

| Files/Group                                                      | Change Summary |
|-----------------------------------------------------------------|----------------|
| `firebase/clientApp.ts`                                         | Refactored Firebase initialization to use named exports, environment variables with `NEXT_PUBLIC_` prefix, and added named export for Firebase Auth. |
| `package.json`                                                  | Added dependencies: `@hookform/resolvers`, `nookies`, and `zod`. |
| `src/app/layout.tsx`                                            | Wrapped layout in `AuthProvider` to provide authentication context throughout the app. |
| `src/app/login/LoginForm.tsx`                                   | Added new `Login` component with form validation, CAPTCHA, password toggle, and Firebase login integration. |
| `src/app/login/page.tsx`                                        | Simplified to render `LoginForm` inside a `Suspense` boundary; removed all form logic. |
| `src/app/login/utils.ts`                                        | Added `userLogin` utility for Firebase authentication with error handling and schema validation. |
| `src/app/login/validation.ts`                                   | Added `loginSchema` using `zod` for email and password validation. |
| `src/app/registration/actions.ts`                               | Added `createUser` async function for user registration, validation, Firebase Authentication account creation, and Firestore user profile saving. |
| `src/app/registration/page.tsx`                                 | Switched to schema-based validation with `zod`, updated form types, and delegated submission to `createUser`. |
| `src/app/registration/validation.ts`                            | Added `registrationSchema` using `zod` for registration form validation. |
| `src/components/Footer/FooterBottom/FooterBottom.tsx`<br>`src/components/Footer/NewsLetter/NewsLetter.tsx` | Changed form value type from `IFormValues` to `FormValues` in `useForm` hooks. |
| `src/constants/constants.ts`                                    | Added constants for authentication cookie name, max age, and token refresh interval. |
| `src/context/AuthContext.tsx`                                   | Introduced `AuthContext`, `AuthProvider`, and hooks for managing authentication state, cookies, and logout functionality. |
| `src/middleware.ts`                                             | Added middleware to enforce authentication on protected routes and redirect unauthenticated users with return URL support. |
| `src/shared/Input/Input.tsx`                                    | Made `Input` component and props generic for flexible form value types. |
| `src/shared/Input/types.ts`                                     | Replaced `IFormValues` with `LoginFormValues`, `RegistrationFormValues`, and union type `FormValues`. |
| `src/shared/Selector/Selector.tsx`                              | Refactored to a generic component for flexible form value typing. |
| `src/types.ts`                                                  | Added `AuthContextType` to model authentication context structure. |

## Possibly related PRs

- **tamadekk/learn-app#4**: Updates Firebase client initialization by switching from default to named exports, adding Firebase Authentication initialization and export, and changing environment variable usage; builds upon initial Firebase client setup introduced in this PR.

## Poem

> In fields of code where carrots grow,  
> A rabbit hops with forms in tow—  
> Now login's safe, with zod and keys,  
> And cookies guard with nimble ease.  
> Context wraps the burrow tight,  
> Middleware keeps out bugs at night.  
> Hippity-hop, the code’s just right! 🥕✨
"""

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 ESLint</summary>
> 
> > If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
> 
> <details>
> <summary>src/middleware.ts</summary>
> 
> 
> Oops! Something went wrong! :(
> 
> ESLint: 9.17.0
> 
> ESLint couldn't find the config "next" to extend from. Please check that the name of the config is correct.
> 
> The config "next" was referenced from the config file in "".
> 
> If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
> 
> 
> </details>
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 3fc8c3c0339897905f08ec299f4afe6d93074cf0 and 37e92793e93c6301155f3a4f136dd6e659cfd46e.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/middleware.ts` (1 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* src/middleware.ts

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEejqANiS4BWFM25W2GXJAv4i8LGjyx28Bmp4fAwDADlsZgFKLgBOAwBVRBjIXDRmNCUAayyjfWNwKDJ6fAAzHAJiMmUaeiZWdi5efmFRcSkZeSYlKlV1LR18kyg4VFRMCsJScipahQaXLioAd0hESIyKeTkFHpU1TW1dMEMC0wNS+AoSATRkgHoGC3h2AEFubg1cRA4DACIAQYAMRAyCvAC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q/CGAtwdi6UCEs2ApeNgQIH8PMpcWIAjAUoIEFiDKXnob0SiwIGQtvQGAaMEgGjGQtoBVL4g0y+ZZsAkAbAD0UyqoECC0BGLhITS1ADRg6XKLaMBgOILRhowKLsQNC+IOUviD8LogN6MJdKAPQ0ALRUyuRYkHIWHoDAUoJIK8tiDkLJAX4WhfMt4WGAplCQbRZsDKW0YaADi89DRhJXaAplEgKZR+HpXiL9VwC/eZAu4AwLbsSCxgheAjRaAWoYoIBaAA -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=tamadekk/learn-app&utm_content=9):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: NONE