Skip to content

Commit

Permalink
Now user can sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
elszczepano committed Oct 2, 2018
1 parent b84707f commit 8d85ede
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dotenv.config({path: '.env'});
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import passport from './config/passport';
import authRouter from './routes/authRouter';
import indexRouter from './routes/indexRouter';
import matchesRouter from './routes/matchesRouter';
Expand All @@ -13,6 +14,9 @@ import usersRouter from './routes/usersRouter';
//Setup Express.js
const app = express();

//Configure passport
passport();

//Setup MongoDB
mongoose.connect(process.env.DB_HOST, { useNewUrlParser: true });
const db = mongoose.connection;
Expand Down
6 changes: 6 additions & 0 deletions src/config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import passport from 'passport';
import User from '../models/User';

export default () => {
passport.use(User.createStrategy())
}
6 changes: 6 additions & 0 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import User from '../models/User';

export default {
async login(req, res, next) {
return res.status(200).json({
message: "User signed in succesfully"
});
},

async register(req, res, next) {
const {name, email, phone, gender, birthDate, purpose, password} = req.body;
const user = new User({name, email, password, phone, gender, birthDate, purpose});
Expand Down
2 changes: 2 additions & 0 deletions src/routes/authRouter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Router } from "express";
import authController from "../controllers/authController";
import passport from 'passport';

const api = Router();

api.post('/login', passport.authenticate('local', { session: false }), authController.login);
api.post('/register', authController.register);

module.exports = api;

0 comments on commit 8d85ede

Please sign in to comment.