Skip to content

Commit 4953fde

Browse files
authored
Merge branch 'main' into pass
2 parents 2f95591 + 53f820b commit 4953fde

4 files changed

Lines changed: 34 additions & 48 deletions

File tree

backend/config/passportConfig.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ passport.use(
77
{ usernameField: "email" },
88
async (email, password, done) => {
99
try {
10-
const user = await User.findOne({ email }).select("+password");
10+
const user = await User.findOne( {email} );
1111
if (!user) {
1212
return done(null, false, { message: 'Email is invalid ' });
1313
}
@@ -38,13 +38,6 @@ passport.serializeUser((user, done) => {
3838
passport.deserializeUser(async (id, done) => {
3939
try {
4040
const user = await User.findById(id);
41-
42-
// 🛡️ Safety check: If the user record no longer exists in MongoDB, exit safely
43-
// This prevents the application from throwing an unhandled TypeError downstream
44-
if (!user) {
45-
return done(null, false); // Gracefully invalidates the cookie and ends the request loop
46-
}
47-
4841
done(null, user);
4942
} catch (err) {
5043
done(err, null);

backend/models/User.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@ const UserSchema = new mongoose.Schema({
1919
});
2020

2121
// ✅ FIXED: no next()
22-
UserSchema.pre('save', async function (next) {
23-
if (!this.isModified('password')) return next();
24-
try {
25-
const salt = await bcrypt.genSalt(10);
26-
this.password = await bcrypt.hash(this.password, salt);
27-
next(); // Tells Mongoose hashing is done, save the document now
28-
} catch (err) {
29-
next(err); // Safely passes any encryption errors to the database handler
30-
}
22+
UserSchema.pre('save', async function () {
23+
if (!this.isModified('password')) return;
24+
25+
const salt = await bcrypt.genSalt(10);
26+
this.password = await bcrypt.hash(this.password, salt);
3127
});
3228

3329
// ✅ password comparison
3430
UserSchema.methods.comparePassword = async function (enteredPassword) {
3531
return bcrypt.compare(enteredPassword, this.password);
3632
};
3733

38-
module.exports = mongoose.model("User", UserSchema);
34+
module.exports = mongoose.model("User", UserSchema);

src/components/ScrollProgressBar.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,18 @@ const ScrollProgressBar = () => {
6161
{/* Scroll progress bar after animation ends */}
6262
{!isAnimating && (
6363
<div
64-
style={{
65-
position: "fixed",
66-
top: 0,
67-
left: 0,
68-
// Dynamically swaps between full width loading animation and real-time scroll updates
69-
width: isAnimating ? "0" : `${scrollWidth}%`,
70-
height: isAnimating ? "2px" : "3px",
71-
backgroundColor: isAnimating ? "blue" : "#3b82f6",
72-
zIndex: 100,
73-
// Applies the loading animation curve ONLY during the initial loading phase
74-
animation: isAnimating ? "slideIn 2s ease-in-out forwards" : "none",
75-
// Applies smooth tracking ticks once scroll tracking takes over
76-
transition: isAnimating ? "none" : "width 0.1s ease",
77-
}}
78-
/>
64+
style={{
65+
position: "fixed",
66+
top: 0,
67+
left: 0,
68+
width: `${scrollWidth}%`,
69+
height: "3px",
70+
backgroundColor: "#3b82f6",
71+
zIndex: 100,
72+
transition: "width 0.1s ease",
73+
}}
74+
/>
75+
)}
7976

8077
{/* Animation Keyframes */}
8178
<style>
@@ -93,3 +90,5 @@ const ScrollProgressBar = () => {
9390
</>
9491
);
9592
};
93+
94+
export default ScrollProgressBar;

src/hooks/useDebounce.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { useState, useEffect, useRef } from "react";
1+
import { useState, useEffect } from 'react';
22

3-
// Inside your custom useDebounce hook function:
4-
const isMounted = useRef(true);
3+
export function useDebounce<T>(value: T, delay: number): T {
4+
const [debouncedValue, setDebouncedValue] = useState<T>(value);
55

6-
useEffect(() => {
7-
isMounted.current = true;
8-
9-
const handler = setTimeout(() => {
10-
if (isMounted.current) {
6+
useEffect(() => {
7+
const handler = setTimeout(() => {
118
setDebouncedValue(value);
12-
}
13-
}, delay);
9+
}, delay);
10+
11+
return () => {
12+
clearTimeout(handler);
13+
};
14+
}, [value, delay]);
1415

15-
return () => {
16-
clearTimeout(handler);
17-
isMounted.current = false;
18-
};
19-
}, [value, delay]);
16+
return debouncedValue;
17+
}

0 commit comments

Comments
 (0)