Skip to content

Commit

Permalink
backend updted
Browse files Browse the repository at this point in the history
  • Loading branch information
harishsg99 authored Feb 25, 2021
1 parent f942721 commit ea8c6d6
Show file tree
Hide file tree
Showing 12 changed files with 4,411 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env"
]
}

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
/client/node_modules
/client/build
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# Kanbanize
Workflow Management Chrome Extension for the Atlassian Hack (IITM)
# Login and registration with MERN stack

![Final App](client/public/mern-auth.gif)
User Registration and Login functionality with validations using React, NodeJs, ExpressJs and MongoDB and authentication using passport and JWTs.

Live Demo: https://mern-login-register.herokuapp.com/

This project uses the following technologies:

- [React](https://reactjs.org) and [React Router](https://reacttraining.com/react-router/) for frontend
- [Express](http://expressjs.com/) and [Node](https://nodejs.org/en/) for the backend
- [MongoDB](https://www.mongodb.com/) for the database
- [Redux](https://redux.js.org/basics/usagewithreact) for state management between React components

## Reference via

- [Build a Login/Auth App with the MERN Stack — Part 1 (Backend)](https://blog.bitsrc.io/build-a-login-auth-app-with-mern-stack-part-1-c405048e3669)


## Quick Start

```
// Install dependencies for server & client
npm install && npm run client-install
// Run client & server with concurrently
npm run dev
// Server runs on http://localhost:5000 and client on http://localhost:3000
```

4 changes: 4 additions & 0 deletions config/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
mongoURI: "mongodb://localhost:27017/mern-auth",
secretOrKey: "secret"
};
24 changes: 24 additions & 0 deletions config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const JwtStrategy = require("passport-jwt").Strategy;
const ExtractJwt = require("passport-jwt").ExtractJwt;
const mongoose = require("mongoose");
const User = mongoose.model("users");
const keys = require("../config/keys");

const opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = keys.secretOrKey;

module.exports = passport => {
passport.use(
new JwtStrategy(opts, (jwt_payload, done) => {
User.findById(jwt_payload.id)
.then(user => {
if (user) {
return done(null, user);
}
return done(null, false);
})
.catch(err => console.log(err));
})
);
};
24 changes: 24 additions & 0 deletions models/UserSchema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// Create Schema
const UserSchema = new Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
}
});

module.exports = mongoose.model("users", UserSchema);
Loading

0 comments on commit ea8c6d6

Please sign in to comment.