Skip to content

Commit 4725330

Browse files
committed
Clean up code: remove inline comments
1 parent 8f8feab commit 4725330

2 files changed

Lines changed: 1 addition & 19 deletions

File tree

src/app/auth/forgot-password/page.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,24 @@ export default function ForgotPasswordPage() {
1616
e.preventDefault();
1717
setLoading(true);
1818

19-
// Validate email domain
2019
if (!isAllowedEmail(email)) {
2120
addToast("Please enter a valid email address.", "error");
2221
setLoading(false);
2322
return;
2423
}
2524

2625
try {
27-
// Smart Fallback Flow:
28-
// 1. We TRY to check if the user exists
2926
const emailExists = await checkEmailExists(email);
3027

31-
// 2. We sending the reset email in BOTH cases
32-
// (This ensures valid users are NEVER blocked, even if Firebase hides them)
3328
await resetPassword(email);
3429

35-
// 3. We show the appropriate message
3630
if (emailExists) {
37-
// If we explicitly found them (Protection OFF)
3831
addToast("Password reset link has been sent to your email.", "success");
3932
} else {
40-
// If we couldn't find them (Protection ON or User Missing)
41-
// We show a safe message and didn't block the email sending!
4233
addToast("If an account exists with this email, a password reset link has been sent.", "success");
4334
}
4435

45-
setEmail(""); // Clear form
36+
setEmail("");
4637
} catch (err: any) {
4738
console.error("Error in handleReset:", err);
4839
addToast("Something went wrong. Please try again later.", "error");

src/lib/firebase/auth.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import { useEffect, useState } from "react";
1414
import { isAllowedEmail } from "../config";
1515

16-
// Auth Hook
1716
export function useAuth() {
1817
const [user, setUser] = useState<User | null>(null);
1918
const [loading, setLoading] = useState(true);
@@ -29,22 +28,19 @@ export function useAuth() {
2928
return { user, loading };
3029
}
3130

32-
// Sign In
3331
export const signIn = async (email: string, pass: string) => {
3432
if (!isAllowedEmail(email)) {
3533
throw new Error("ACCESS_DENIED");
3634
}
3735
const userCredential = await signInWithEmailAndPassword(auth, email, pass);
3836

39-
// Check if email is verified
4037
if (!userCredential.user.emailVerified) {
4138
throw new Error("EMAIL_NOT_VERIFIED");
4239
}
4340

4441
return userCredential;
4542
};
4643

47-
// Sign Up (for initial seeding or admin use)
4844
export const signUp = async (name: string, email: string, pass: string) => {
4945

5046
if (!isAllowedEmail(email)) {
@@ -57,25 +53,20 @@ export const signUp = async (name: string, email: string, pass: string) => {
5753
return userCredential;
5854
};
5955

60-
// Sign Out
6156
export const signOut = () => firebaseSignOut(auth);
6257

63-
// Check if email exists
6458
export const checkEmailExists = async (email: string): Promise<boolean> => {
6559
try {
6660
const methods = await fetchSignInMethodsForEmail(auth, email);
6761
return methods.length > 0;
6862
} catch (error: any) {
69-
// If error code is auth/invalid-email, the email format is wrong
7063
if (error.code === 'auth/invalid-email') {
7164
return false;
7265
}
73-
// For other errors, return false to be safe
7466
console.error("Error checking email existence:", error);
7567
return false;
7668
}
7769
};
7870

79-
// Password Reset
8071
export const resetPassword = (email: string) =>
8172
sendPasswordResetEmail(auth, email);

0 commit comments

Comments
 (0)