diff --git a/src/app.js b/src/app.js index 443b132..edf234c 100644 --- a/src/app.js +++ b/src/app.js @@ -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'; @@ -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; diff --git a/src/config/passport.js b/src/config/passport.js new file mode 100644 index 0000000..3697202 --- /dev/null +++ b/src/config/passport.js @@ -0,0 +1,6 @@ +import passport from 'passport'; +import User from '../models/User'; + +export default () => { + passport.use(User.createStrategy()) +} \ No newline at end of file diff --git a/src/controllers/authController.js b/src/controllers/authController.js index b7901f8..cceb791 100644 --- a/src/controllers/authController.js +++ b/src/controllers/authController.js @@ -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}); diff --git a/src/routes/authRouter.js b/src/routes/authRouter.js index c1a2ca9..b66209e 100644 --- a/src/routes/authRouter.js +++ b/src/routes/authRouter.js @@ -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; \ No newline at end of file