-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
715 additions
and
256 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Project Setup | ||
|
||
This guide will help you set up the project on your local machine. | ||
|
||
## Step 1: Install Dependencies | ||
|
||
First, you need to install the project dependencies. Run the following command in your terminal: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Step 2: Set Up Environment Variables | ||
|
||
There is an example.env.txt file in the project root. Create a new file named .env in the same location and copy the contents of example.env.txt into it. | ||
|
||
In the .env file, you will find a placeholder for MONGODB_URL credential. Replace it with your actual credentials. | ||
|
||
If you’re running MongoDB locally, your database link will look something like this: | ||
|
||
```bash | ||
mongodb://localhost:27017/mydatabase | ||
``` | ||
|
||
If you’re using a cloud database service like MongoDB Atlas, your database link will be provided by the service.which will look something like this: | ||
|
||
- replace the password with actual password | ||
|
||
```bash | ||
mongodb+srv://databasename:<password>@something.banc821.mongodb.net/ | ||
``` | ||
|
||
## Step 3: Start the Server | ||
|
||
To start the server, run the following command: | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
Now, your server should be up and running! | ||
|
||
## Step 4: Access the Server | ||
|
||
You can access the server by typing http://localhost:<port_number> in your browser, where <port_number> is the port number on which your server is running. the default port is 3000: | ||
|
||
```bash | ||
http://localhost:3000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const mongoose = require("mongoose"); | ||
function dbConfig() { | ||
mongoose | ||
.connect(process.env.MONGODB_URL, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}) | ||
.then(() => { | ||
console.log("Connected to MongoDB"); | ||
// Start your application logic here | ||
}) | ||
.catch((err) => { | ||
console.error("Error connecting to MongoDB:", err); | ||
process.exit(1); | ||
}); | ||
} | ||
module.exports = dbConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const passport = require("passport"); | ||
const LocalStrategy = require("passport-local").Strategy; | ||
const bcrypt = require("bcrypt"); | ||
|
||
const User = require("../db/User"); | ||
|
||
passport.use( | ||
new LocalStrategy(async (username, password, done) => { | ||
try { | ||
const user = await User.findOne({ username: username }); | ||
|
||
if (!user) { | ||
return done(null, false, { message: "Incorrect username." }); | ||
} | ||
|
||
const passwordMatch = await bcrypt.compare(password, user.password); | ||
|
||
if (!passwordMatch) { | ||
return done(null, false, { message: "Incorrect password." }); | ||
} | ||
|
||
return done(null, user); | ||
} catch (err) { | ||
return done(err); | ||
} | ||
}) | ||
); | ||
|
||
passport.serializeUser((user, done) => { | ||
done(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser((id, done) => { | ||
User.findById(id) | ||
.then((user) => { | ||
done(null, user); | ||
}) | ||
.catch((err) => { | ||
done(err); | ||
}); | ||
}); |
Oops, something went wrong.