Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cbefec9
chore(config): move db connection and passport strategy to config folder
codewkaushik404 Jan 29, 2026
78dbc24
fix(schema): update user schema to support correct login and registra…
codewkaushik404 Jan 29, 2026
f2e5883
refactor(auth): replace passport-local-mongoose with manual auth impl…
codewkaushik404 Jan 29, 2026
ae0295f
feat(validation): add zod validation for auth routes with IIT Bhilai …
codewkaushik404 Jan 29, 2026
57c4189
feat(auth): add manual JWT authentication middleware
codewkaushik404 Jan 30, 2026
61dfd89
refactor(schema): update certificate schema
codewkaushik404 Jan 30, 2026
29bc583
feat(certificates): implement controller logic to create certificate …
codewkaushik404 Jan 30, 2026
a8b4d8e
feat(certificates): implement controller logic to create certificate …
codewkaushik404 Jan 30, 2026
82d3b70
feat(validation): add Zod schema to validate certificate batch creati…
codewkaushik404 Jan 30, 2026
bde7d5e
Fix crashes and ensure intended behavior
codewkaushik404 Jan 30, 2026
ecc1ebd
refactor(auth): split schemas into separate files and fix local auth …
codewkaushik404 Feb 9, 2026
8126097
refactor(auth, models, middleware): refactor code to ensure robust l…
codewkaushik404 Feb 9, 2026
4e96a8e
Refactored authentication logic and fixed related bugs.
codewkaushik404 Feb 17, 2026
d3c0261
Refactored authentication logic and fixed related bugs. Switched to s…
codewkaushik404 Feb 17, 2026
2a31781
refactor few segments
codewkaushik404 Feb 17, 2026
53d7216
fix: api responses to handle frontend requirements
codewkaushik404 Feb 17, 2026
cdf07e2
refactor
codewkaushik404 Feb 17, 2026
c342d2b
fix: imports for models in controllers according to the updated struc…
codewkaushik404 Feb 17, 2026
649fb09
fix: imports for models in controllers according to the updated struc…
codewkaushik404 Feb 17, 2026
3fe6ed8
refactor
codewkaushik404 Feb 17, 2026
f521062
refactor: streamline authentication and registration processes, enhan…
codewkaushik404 Feb 18, 2026
2ef2e05
fix: incorrect imports for models in routes.
codewkaushik404 Feb 19, 2026
0f47b6a
refactor: improve auth flow
codewkaushik404 Feb 19, 2026
0bd1220
feat: add certificate page and update navbar config for role-based ac…
codewkaushik404 Feb 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions backend/config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();

const connectDB = async () => {
try {
const ConnectDB = process.env.MONGODB_URI;
//Removing the options as they are no longer needed from mongoose6+
await mongoose.connect(ConnectDB);
console.log("MongoDB Connected");
} catch (error) {
console.error("MongoDB Connection Error:", error);
}
};
// connectDB()

const closeDB = () => {
mongoose.connection
.close()
.then(() => {
console.log("MongoDB connection closed");
})
.catch((err) => {
console.error("Error while closing MongoDB connection:", err);
});
};

// Call the connectDB function to establish the MongoDB connection

module.exports = { connectDB, closeDB };
67 changes: 67 additions & 0 deletions backend/config/passportConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20");
Comment thread
codewkaushik404 marked this conversation as resolved.
Outdated
const isIITBhilaiEmail = require("../utils/isIITBhilaiEmail");
const { User } = require("../models/schema");

// Google OAuth Strategy
passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: `${process.env.BACKEND_URL}/auth/google/verify`, // Update with your callback URL
},
async (accessToken, refreshToken, profile, done) => {
// Check if the user already exists in your database
if (!isIITBhilaiEmail(profile.emails[0].value)) {
console.log("Google OAuth blocked for: ", profile.emails[0].value);
return done(null, false, {
message: "Only @iitbhilai.ac.in emails are allowed.",
});
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
try {
const user = await User.findOne({ username: profile.emails[0].value });

if (user) {
// If user exists, return the user
return done(null, user);
}
// If user doesn't exist, create a new user in your database
const newUser = new User({
username: profile.emails[0].value,
role: "STUDENT",
strategy: "google",
personal_info: {
name: profile.displayName || "No Name",
email: profile.emails[0].value,
profilePic:
profile.photos && profile.photos.length > 0
? profile.photos[0].value
: "https://www.gravatar.com/avatar/?d=mp",
},
onboardingComplete: false,
});

await newUser.save();
return done(null, newUser);
} catch (error) {
return done(error);
}
},
),
);

passport.serializeUser((user, done) => {
done(null, user);
});

passport.deserializeUser(async (userKey, done) => {
try {
let user = await User.findById(userKey._id);
done(null, user);
} catch (err) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
done(err);
}
});

module.exports = passport;
140 changes: 69 additions & 71 deletions backend/models/schema.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,90 @@
const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");
var findOrCreate = require("mongoose-findorcreate");
//user collection

const userSchema = new mongoose.Schema({
user_id: {
type: String,
},
role: {
type: String,
required: true,
},
strategy: {
type: String,
enum: ["local", "google"],
required: true,
},
username: {
type: String,
required: true,
unique: true,
},
onboardingComplete: {
type: Boolean,
default: false,
},
personal_info: {
name: {
const userSchema = new mongoose.Schema(
{
user_id: {
type: String,
},
role: {
type: String,
required: true,
},
email: {
strategy: {
type: String,
enum: ["local", "google"],
required: true,
},
phone: String,
date_of_birth: Date,
gender: String,

profilePic: {
username: {
type: String,
default: "https://www.gravatar.com/avatar/?d=mp",
required: true,
unique: true,
},

cloudinaryUrl: {
password: {
type: String,
default: "",
required: function () {
return this.strategy === "local";
},
minLength: 8,
},
},
onboardingComplete: {
type: Boolean,
default: false,
},
personal_info: {
name: {
type: String,
required: true,
},
email: {
type: String,
},
phone: String,
date_of_birth: Date,
gender: String,

academic_info: {
program: {
type: String,
//enum: ["B.Tech", "M.Tech", "PhD", "Msc","other"],
profilePic: {
type: String,
default: "https://www.gravatar.com/avatar/?d=mp",
},

cloudinaryUrl: {
type: String,
default: "",
},
},
branch: String,
batch_year: String,
current_year: String,
cgpa: Number,
},

contact_info: {
hostel: String,
room_number: String,
socialLinks: {
github: { type: String, default: "" },
linkedin: { type: String, default: "" },
instagram: { type: String, default: "" },
other: { type: String, default: "" },
academic_info: {
program: {
type: String,
//enum: ["B.Tech", "M.Tech", "PhD", "Msc","other"],
},
branch: String,
batch_year: String,
current_year: String,
cgpa: Number,
},
},

status: {
type: String,
enum: ["active", "inactive", "graduated"],
default: "active",
},
created_at: {
type: Date,
default: Date.now,
contact_info: {
hostel: String,
room_number: String,
socialLinks: {
github: { type: String, default: "" },
linkedin: { type: String, default: "" },
instagram: { type: String, default: "" },
other: { type: String, default: "" },
},
},

status: {
type: String,
enum: ["active", "inactive", "graduated"],
default: "active",
},
},
updated_at: {
type: Date,
default: Date.now,
{
timestamps: true,
},
});
);

userSchema.index(
{ user_id: 1 },
Expand All @@ -94,9 +95,6 @@ userSchema.index(
},
);

userSchema.plugin(passportLocalMongoose);
userSchema.plugin(findOrCreate);

//organizational unit
const organizationalUnitSchema = new mongoose.Schema({
unit_id: {
Expand Down
Loading