Skip to content

Commit 4c4f8cd

Browse files
Restore repository to v1.0.2 state
1 parent adff9a0 commit 4c4f8cd

43 files changed

Lines changed: 873 additions & 5154 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SECURITY.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

backend/.env.example

Lines changed: 0 additions & 14 deletions
This file was deleted.

backend/config/passportConfig.js

Lines changed: 3 additions & 7 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
}
@@ -20,8 +20,7 @@ passport.use(
2020
return done(null, {
2121
id : user._id.toString(),
2222
username: user.username,
23-
email: user.email,
24-
token: user.token
23+
email: user.email
2524
});
2625
} catch (err) {
2726
return done(err);
@@ -39,10 +38,7 @@ passport.serializeUser((user, done) => {
3938
passport.deserializeUser(async (id, done) => {
4039
try {
4140
const user = await User.findById(id);
42-
if (!user) {
43-
return done(null, false);
44-
}
45-
done(null,user);
41+
done(null, user);
4642
} catch (err) {
4743
done(err, null);
4844
}

backend/models/User.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ const UserSchema = new mongoose.Schema({
1616
type: String,
1717
required: true,
1818
},
19-
token: {
20-
type: String,
21-
unique: true,
22-
sparse: true,
23-
},
2419
});
2520

2621
// ✅ FIXED: no next()
27-
UserSchema.pre("save", async function () {
28-
if (!this.isModified("password")) return;
22+
UserSchema.pre('save', async function () {
23+
if (!this.isModified('password')) return;
2924

3025
const salt = await bcrypt.genSalt(10);
3126
this.password = await bcrypt.hash(this.password, salt);
@@ -36,5 +31,4 @@ UserSchema.methods.comparePassword = async function (enteredPassword) {
3631
return bcrypt.compare(enteredPassword, this.password);
3732
};
3833

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

backend/routes/auth.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,6 @@ router.post("/login", validateRequest(loginSchema), passport.authenticate('local
3535
res.status(200).json( { message: 'Login successful', user: req.user } );
3636
});
3737

38-
// Save GitHub token route
39-
router.post("/token", async (req, res) => {
40-
if (!req.isAuthenticated()) {
41-
return res.status(401).json({ message: 'Not authenticated' });
42-
}
43-
const { token } = req.body;
44-
if (!token) {
45-
return res.status(400).json({ message: 'Token is required' });
46-
}
47-
try {
48-
await User.findByIdAndUpdate(req.user._id, { token });
49-
req.user.token = token;
50-
res.status(200).json({ success: true, message: 'Token saved successfully' });
51-
} catch (err) {
52-
res.status(500).json({ message: 'Error saving token', error: err.message });
53-
}
54-
});
55-
5638
// Logout route
5739
router.get("/logout", (req, res) => {
5840

backend/server.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@ const logger = require('./logger');
1313

1414
const app = express();
1515

16-
// CORS configuration — allowed origins are read from the ALLOWED_ORIGINS env var
17-
// (comma-separated). Falls back to localhost for local development.
18-
const parsedOrigins = process.env.ALLOWED_ORIGINS
19-
? process.env.ALLOWED_ORIGINS.split(',').map(origin => origin.trim()).filter(Boolean)
20-
: [];
21-
const allowedOrigins = parsedOrigins.length > 0 ? parsedOrigins : ['http://localhost:5173'];
22-
16+
// CORS configuration
17+
const allowedOrigins = ['http://localhost:5173', 'https://github-spy.etlify.app'];
2318
app.use(cors({
2419
origin: function (origin, callback) {
25-
// Allow requests with no origin (e.g. server-to-server, curl, mobile apps)
2620
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
2721
callback(null, true);
28-
} else {
22+
} else{
2923
callback(new Error('Blocked by CORS policy'));
3024
}
3125
},

backend/validators/authValidator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const signupSchema = z.object({
66
.min(3, "Username must be at least 3 characters long")
77
.max(30, "Username must be at most 30 characters long")
88
.regex(/^[a-zA-Z0-9_]+$/, "Username can only contain letters, numbers, and underscores")
9-
,
10-
9+
,
10+
1111
email: z.string()
1212
.trim()
1313
.toLowerCase()
@@ -18,7 +18,7 @@ const signupSchema = z.object({
1818
.min(8, "Password must be at least 8 characters long")
1919
.max(100, "Password must be at most 100 characters long")
2020
.regex(
21-
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}+$/,
21+
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
2222
'Password must contain uppercase, lowercase, number, and special character'
2323
),
2424
});

0 commit comments

Comments
 (0)