forked from Open-Source-Chandigarh/Euphoria-Check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
30 lines (29 loc) · 816 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require("dotenv").config()
//MongoDB connection for login and signup
const mongoose=require("mongoose")
const connect=mongoose.connect(process.env.Mongo_URL)
connect.then(()=>{
console.log("connected to DB successfully")
})
.catch(()=>{
console.log("error connecting to DB")
})
// Custom email validator function
function validateEmail(email) {
// Regular expression for email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
const loginSchema=new mongoose.Schema({
email:{
type:String,
required:true,
validate: [validateEmail, 'Please fill a valid email address']
},
password:{
type:String,
required:true
}
});
const collection=new mongoose.model("users",loginSchema)
module.exports=collection;