diff --git a/back-end/src/app.mjs b/back-end/src/app.mjs index 19e266f..56421e8 100644 --- a/back-end/src/app.mjs +++ b/back-end/src/app.mjs @@ -1,18 +1,16 @@ import express from 'express'; import url from 'url'; import path from 'path'; -// middlewares import multer from "multer"; -import bcrypt from 'bcryptjs'; import cors from 'cors'; -import "dotenv/config"; import dotenv from 'dotenv'; import morgan from 'morgan'; import session from 'express-session'; import mongoose from 'mongoose'; import { body, validationResult } from 'express-validator'; import jwt from 'jsonwebtoken'; - +import passport from 'passport' +import CustomJwtStrategy from './config/jwt-config.mjs'; // routes import loginRouter from './routes/loginRouter.mjs'; import registerRouter from './routes/registerRouter.mjs'; @@ -23,11 +21,9 @@ import getpieceRouter from './routes/getpieceRouter.mjs'; import resetpasswordRouter from './routes/resetpasswordRouter.mjs'; import resetemailRouter from './routes/resetemailRouter.mjs'; import searchArtsRouter from './routes/searchArtsRouter.mjs'; - import {addFavListRouter,favListRouter, getArts} from './routes/modifyFavListRouter.mjs' -import { configDotenv } from 'dotenv'; -const app = express(); +const app = express(); // use the morgan middleware to log all incoming http requests app.use(morgan("dev")); @@ -66,7 +62,11 @@ app.use(session({ })) console.log('Session secret:', process.env.SESSION_SECRET); -// other middlewares +// jwt strategy +passport.use(CustomJwtStrategy) + +// initialize passport +app.use(passport.initialize()) // routes that does not need authentication // app.post("/getpiece", getpieceRouter); @@ -101,8 +101,6 @@ const passwordValidationRules = [ // Optionally, include checks for special characters or uppercase letters ]; - - // routes that needs authentication // Account routes app.patch("/changeusername", usernameValidationRules, changeusernameRouter); //Finished diff --git a/back-end/src/config/jwt-config.mjs b/back-end/src/config/jwt-config.mjs index 9904129..930aa28 100644 --- a/back-end/src/config/jwt-config.mjs +++ b/back-end/src/config/jwt-config.mjs @@ -26,6 +26,8 @@ const jwtVerifyToken = async function (jwt_payload, done) { } } -const jwtStrategy = new JwtStrategy(jwtOptions, jwtVerifyToken) +const CustomJwtStrategy = () => { + return new JwtStrategy(jwtOptions, jwtVerifyToken) +} -export default jwtStrategy \ No newline at end of file +export default CustomJwtStrategy \ No newline at end of file