Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var cors = require('cors')

const app = express();
app.use(cors())
app.use(express.json());

app.get('/', (req, res) => {
res.send('Hello World!');
Expand Down
19 changes: 19 additions & 0 deletions backend/lib/hashPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const bcrypt = require('bcrypt');

/**
* Hashes a plain text password using bcrypt.
* @param {string} password - The plain text password to hash.
* @returns {Promise<string>} The hashed password.
*/
async function hashPassword(password) {
try {
const saltRounds = 10; // Number of salt rounds for bcrypt
const hashedPassword = await bcrypt.hash(password, saltRounds);
return hashedPassword;
} catch (err) {
console.error('Error hashing password:', err);
throw new Error('Error hashing password');
}
}

module.exports = hashPassword;
27 changes: 27 additions & 0 deletions backend/models/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mongoose = require("mongoose");

// Define the schema for the User model
const authSchema = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true, // Ensures no duplicate emails in the database
trim: true, // Removes any extra spaces from the input
match: [/.+@.+\..+/, "Please enter a valid email address"], // Regex for email validation
},
password: {
type: String,
required: true,
minlength: 6, // Ensures the password is at least 6 characters
},
createdAt: {
type: Date,
default: Date.now, // Automatically sets the current date and time
},
});

// Create the User model
const Auth = mongoose.model("Auth", authSchema);

// Export the model
module.exports = Auth;
Loading