Skip to content

Commit

Permalink
add passport middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina1o1 committed Dec 7, 2023
1 parent f79465d commit 043722d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 8 additions & 10 deletions back-end/src/app.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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"));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions back-end/src/config/jwt-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
export default CustomJwtStrategy

0 comments on commit 043722d

Please sign in to comment.