Skip to content

Commit

Permalink
Merge pull request #109 from hngx-org/dev_correction
Browse files Browse the repository at this point in the history
Dev correction
  • Loading branch information
gr4yx01 authored Sep 23, 2023
2 parents 79ed35a + 401c89d commit fe31a19
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ app.use(express.urlencoded({ extended: true }));

app.use(
cookieSession({
name: "server",
key: process.env.KEY, // The name of the cookie to store the session data
secret: process.env.SECRET, // A secret string used to sign and encrypt the cookie
maxAge: 24 * 60 * 60 * 1000, // The maximum age of the cookie in milliseconds
Expand Down
20 changes: 11 additions & 9 deletions controllers/userController/methods/loginGoogle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
function authGoogle(req, res,next) {
if(req.isAuthenticated()) {
res.send('Hello ' + req.user[0].name); // Should redirect to homepage in app
} else {
res.redirect('/');
}
}

export default authGoogle;
import {
errorResponse,
successResponse,
} from "../../../utils/helpers/response.helpers.js";
function authGoogle(req, res) {
if (req.isAuthenticated())
return successResponse(res, "authenticated", { user: req.user }, 200);
return errorResponse(res, "failed authentication", 401);
}

export default authGoogle;
1 change: 1 addition & 0 deletions middleware/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ passport.use(
return done(null, user);
})
.catch((err) => {
console.log(err);
return done(new Error("Internal Server Error"));
});
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"http-status-codes": "^2.3.0",
"joi": "^17.10.2",
"mysql2": "^3.6.1",
"passport": "^0.6.0",
"passport": "~0.5",
"passport-google-oauth2": "^0.2.0",
"passport-twitter": "^1.0.4",
"sequelize": "^6.33.0",
Expand Down
5 changes: 1 addition & 4 deletions routes/authRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ authRouter.get(
authRouter.get("/auth/twitter", passport.authenticate("twitter"));
authRouter.get(
"/auth/callback/google",
passport.authenticate("google", {
failureRedirect: "/",
failureMessage: true,
}),
passport.authenticate("google"),
loginGoogle,
);
authRouter.get("/auth/callback/twitter", loginTwitter);
Expand Down
17 changes: 7 additions & 10 deletions routes/eventRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@ import {
createEvent,
getEventDetails,
listAllEvents,
deleteEvent
deleteEvent,
} from "../controllers/eventController/index.js";
import validate from "../middleware/validation.js";

import {
AddCommentToEvent
} from "../controllers/commentController/index.js"
import { AddCommentToEvent } from "../controllers/commentController/index.js";
import { userAuthorisation } from "../middleware/authorization.js";


const eventRouter = express.Router();

/* userAuthorisation middleware needs to
be imported and passed before the validate.Event
in the createEvent route. It requires the req.session.userId. Ypu can refer to the createEvent method in the event controller */
eventRouter.post("/events",userAuthorisation, validate.Event, createEvent);
eventRouter.get("/events",userAuthorisation, listAllEvents);
eventRouter.get("/events/:id",userAuthorisation, getEventDetails);
eventRouter.delete("/events/:id",userAuthorisation, deleteEvent);
eventRouter.post("/events", userAuthorisation, validate.Event, createEvent);
eventRouter.get("/events", userAuthorisation, listAllEvents);
eventRouter.get("/events/:id", userAuthorisation, getEventDetails);
eventRouter.delete("/events/:id", userAuthorisation, deleteEvent);

eventRouter.post("/events/:eventId", AddCommentToEvent);
eventRouter.post("/events/:eventId", userAuthorisation, AddCommentToEvent);

export default eventRouter;

0 comments on commit fe31a19

Please sign in to comment.