From 96d9b38d301735aae637462fc07ba199a9462717 Mon Sep 17 00:00:00 2001 From: Aryan Raj Date: Sun, 24 May 2026 12:44:24 +0530 Subject: [PATCH 1/5] User.js Updated pre-save hook to include next() for proper middleware flow and error handling. --- backend/models/User.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/models/User.js b/backend/models/User.js index eb506ed5..fed589a9 100644 --- a/backend/models/User.js +++ b/backend/models/User.js @@ -19,11 +19,15 @@ const UserSchema = new mongoose.Schema({ }); // ✅ FIXED: no next() -UserSchema.pre('save', async function () { - if (!this.isModified('password')) return; - - const salt = await bcrypt.genSalt(10); - this.password = await bcrypt.hash(this.password, salt); +UserSchema.pre('save', async function (next) { + if (!this.isModified('password')) return next(); + try { + const salt = await bcrypt.genSalt(10); + this.password = await bcrypt.hash(this.password, salt); + next(); // Tells Mongoose hashing is done, save the document now + } catch (err) { + next(err); // Safely passes any encryption errors to the database handler + } }); // ✅ password comparison @@ -31,4 +35,4 @@ UserSchema.methods.comparePassword = async function (enteredPassword) { return bcrypt.compare(enteredPassword, this.password); }; -module.exports = mongoose.model("User", UserSchema); \ No newline at end of file +module.exports = mongoose.model("User", UserSchema); From 0fa4b263bd2ad49917d5f54466ac434cb6e1c34c Mon Sep 17 00:00:00 2001 From: Aryan Raj Date: Sun, 24 May 2026 19:21:53 +0530 Subject: [PATCH 2/5] passportConfig.js --- backend/config/passportConfig.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/config/passportConfig.js b/backend/config/passportConfig.js index 842f50ca..173ff8a9 100644 --- a/backend/config/passportConfig.js +++ b/backend/config/passportConfig.js @@ -7,7 +7,7 @@ passport.use( { usernameField: "email" }, async (email, password, done) => { try { - const user = await User.findOne( {email} ); + const user = await User.findOne( {email} ).select("+password");; if (!user) { return done(null, false, { message: 'Email is invalid '}); } @@ -38,7 +38,10 @@ passport.serializeUser((user, done) => { passport.deserializeUser(async (id, done) => { try { const user = await User.findById(id); - done(null, user); + if (!user) { + return done(null, false); + } + done(null,user); } catch (err) { done(err, null); } From 785a77194211aa78c8d3aebd2821067e20d7b7ad Mon Sep 17 00:00:00 2001 From: Aryan Raj Date: Sun, 24 May 2026 19:43:29 +0530 Subject: [PATCH 3/5] useDebounce.ts --- src/hooks/useDebounce.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/useDebounce.ts b/src/hooks/useDebounce.ts index e3706e6b..93625446 100644 --- a/src/hooks/useDebounce.ts +++ b/src/hooks/useDebounce.ts @@ -1,15 +1,16 @@ import { useState, useEffect } from 'react'; - -export function useDebounce(value: T, delay: number): T { - const [debouncedValue, setDebouncedValue] = useState(value); - +const isMounted = useRef(true); useEffect(() => { + isMounted.current = true; const handler = setTimeout(() => { - setDebouncedValue(value); + if (isMounted.current) { + setDebouncedValue(value); + } }, delay); return () => { clearTimeout(handler); + isMounted.current = false; / }; }, [value, delay]); From e594b98eaa5be13c1d078bc59f37d509f539b8d5 Mon Sep 17 00:00:00 2001 From: Aryan Raj Date: Sun, 24 May 2026 19:48:58 +0530 Subject: [PATCH 4/5] Refactor useDebounce hook for better readability --- src/hooks/useDebounce.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/hooks/useDebounce.ts b/src/hooks/useDebounce.ts index 93625446..44395cef 100644 --- a/src/hooks/useDebounce.ts +++ b/src/hooks/useDebounce.ts @@ -1,18 +1,19 @@ -import { useState, useEffect } from 'react'; -const isMounted = useRef(true); - useEffect(() => { - isMounted.current = true; - const handler = setTimeout(() => { - if (isMounted.current) { - setDebouncedValue(value); - } - }, delay); +import { useState, useEffect, useRef } from "react"; - return () => { - clearTimeout(handler); - isMounted.current = false; / - }; - }, [value, delay]); +// Inside your custom useDebounce hook function: +const isMounted = useRef(true); - return debouncedValue; -} +useEffect(() => { + isMounted.current = true; + + const handler = setTimeout(() => { + if (isMounted.current) { + setDebouncedValue(value); + } + }, delay); + + return () => { + clearTimeout(handler); + isMounted.current = false; + }; +}, [value, delay]); From 9b1e0bd5a23768fa282bec3296281c34ff2696f2 Mon Sep 17 00:00:00 2001 From: Aryan Raj Date: Sun, 24 May 2026 20:02:58 +0530 Subject: [PATCH 5/5] ScrollProgressBar.tsx --- src/components/ScrollProgressBar.tsx | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/components/ScrollProgressBar.tsx b/src/components/ScrollProgressBar.tsx index 34e38116..b56ecece 100644 --- a/src/components/ScrollProgressBar.tsx +++ b/src/components/ScrollProgressBar.tsx @@ -61,18 +61,21 @@ const ScrollProgressBar = () => { {/* Scroll progress bar after animation ends */} {!isAnimating && (
- )} + style={{ + position: "fixed", + top: 0, + left: 0, + // Dynamically swaps between full width loading animation and real-time scroll updates + width: isAnimating ? "0" : `${scrollWidth}%`, + height: isAnimating ? "2px" : "3px", + backgroundColor: isAnimating ? "blue" : "#3b82f6", + zIndex: 100, + // Applies the loading animation curve ONLY during the initial loading phase + animation: isAnimating ? "slideIn 2s ease-in-out forwards" : "none", + // Applies smooth tracking ticks once scroll tracking takes over + transition: isAnimating ? "none" : "width 0.1s ease", + }} + /> {/* Animation Keyframes */}