From f3dff5ff803a14f7e1b8858e5a298f006474e18b Mon Sep 17 00:00:00 2001 From: Maciej Kotowski Date: Wed, 6 Oct 2021 21:45:39 +0200 Subject: [PATCH] things --- client/src/pages/Dashboard/index.js | 2 +- client/src/utils/APIClient.js | 2 ++ index.js | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client/src/pages/Dashboard/index.js b/client/src/pages/Dashboard/index.js index 974371c..ea841bc 100644 --- a/client/src/pages/Dashboard/index.js +++ b/client/src/pages/Dashboard/index.js @@ -8,7 +8,7 @@ import { LOGIN_MANAGER } from "../../constants"; export const Dashboard = () => { useEffect(() => { //chce wyrenderować eventpreview ale tylko dla eventów utworzonych przez danego użytkownika - console.log(API_CLIENT.getUserEvents({email:"GRZANA"}).then((d) => {console.log(d)})) + console.log(API_CLIENT.getUserEvents({email:"test@gmail.com"}).then((d) => {console.log(d)})) }, []); const [list, updateList] = useState( ['o','i'].map((e, i) => { diff --git a/client/src/utils/APIClient.js b/client/src/utils/APIClient.js index 97cac7a..96cacb6 100644 --- a/client/src/utils/APIClient.js +++ b/client/src/utils/APIClient.js @@ -23,7 +23,9 @@ export class APIClient extends EventEmitter { return rq.data; } async getUserEvents(data) { + console.log(data); const rq = await axios.post(`${this.#dbUrl}/api/getUserEvents`, data); + console.log(rq); if (rq.status !== 200) throw new Error(`Request failed with status code ${rq.status}: ${rq.statusText}`); return rq.data; } diff --git a/index.js b/index.js index 0e5a642..1e5c7ac 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const port = process.env.PORT || 5000; const mongoose = require("mongoose"); const session = require("express-session"); const events = require("./models/events"); +const users = require("./models/users"); const passport = require("./passport/setup"); const auth = require("./routes/auth"); app.use( @@ -30,8 +31,11 @@ app.use(express.urlencoded({ extended: false })); app.use( session({ secret: "very secret this is", - resave: false, + resave: true, saveUninitialized: true, + cookie: { + maxAge: 24 * 60 * 60 * 1000 + }, store: MongoStore.create({ mongoUrl: process.env.MONGO_URI }), }) ); @@ -42,7 +46,7 @@ app.use(passport.session()); app.get("/api/isLogged", async (req, res) => { if (req.user) { - res.status(200).json({email:req.user.email,session:req.sessionID}); + res.status(200).json(req.user); } else { res.redirect('/login'); } @@ -75,19 +79,19 @@ app.get("/api/getEvents", async (req, res) => { } }); -app.get("/api/getUserEvents", async (req, res) => { - if (req.user) { +app.post("/api/getUserEvents", async (req, res) => { + // if (req.user) { try { - const event = await events.find({email:req.body.email}); - if (!event) throw Error("something went wrong"); - console.log(event); - res.status(200).json(event); + const user = await users.findOne({email:req.body.email}); + console.log(req.body.email); + if (!user) throw Error("something went wrong"); + res.status(200).json(user); } catch (err) { res.status(400).json({ msg: err }); } - } else { + /* } else { res.redirect('/login'); - } + }*/ }); app.post("/api/createEvent", (req, res) => {