diff --git a/server/app.js b/server/app.js index 07c5d0f2..487d6ff8 100644 --- a/server/app.js +++ b/server/app.js @@ -117,13 +117,13 @@ if (!process.env.NODE_ENV || process.env.NODE_ENV !== 'production') { maxAge: 3600000, // 1 Hour secure: true, httpOnly: true, - domain: 'example.com', - path: 'foo/bar', + domain: 'mondaymorning.nitrkl.ac.in', + path: '/', expires: new Date(Date.now() + 60 * 60 * 1000), // 1 hour }, store, - resave: false, - saveUninitialized: false, + resave: true, + saveUninitialized: true, }) ); } diff --git a/server/router/index.js b/server/router/index.js index e2dc03e1..14a3a5f9 100644 --- a/server/router/index.js +++ b/server/router/index.js @@ -56,17 +56,7 @@ router.use('/admin/spotify/auth', async (_req, res) => { } }); -router.use('/admin/media/auth', async (req, res) => { - const { authToken, decodedToken } = await UserAuth.getContext(req); - - if (!authToken || !decodedToken || !UserPermission.exists(req.session, authToken, decodedToken, 'media.write.new')) { - return res.status(401).json({ - data: 'The user is not authorized to access media endpoint.', - code: 401, - error: true, - }); - } - +router.use('/admin/media/auth', (req, res) => { try { const imagekit = new ImageKit({ publicKey: process.env.IMAGEKIT_PUBLIC_KEY, diff --git a/server/utils/userAuth/index.js b/server/utils/userAuth/index.js index 90a594c4..b0c4fe21 100644 --- a/server/utils/userAuth/index.js +++ b/server/utils/userAuth/index.js @@ -68,15 +68,18 @@ const UserAuth = { } const { uid, exp, roles, mid } = _decodedToken; - req.session.auth = { - uid, - mid, - jwt: req.headers.authorization, - exp, - roles, - decodedToken: _decodedToken, - }; - await req.session.save(); + + if (req.session) { + req.session.auth = { + uid, + mid, + jwt: req.headers.authorization, + exp, + roles, + decodedToken: _decodedToken, + }; + await req.session.save(); + } return { authToken: req.headers.authorization, diff --git a/server/utils/userAuth/session.js b/server/utils/userAuth/session.js index f9bb6e3b..d981f88b 100644 --- a/server/utils/userAuth/session.js +++ b/server/utils/userAuth/session.js @@ -17,7 +17,7 @@ const UserSession = { !session.auth || !session.auth.jwt || !session.auth.exp || - !session.auth.roles || + !session.auth.uid || session.auth.jwt !== jwt || session.auth.exp <= Date.now() / 1000 ? false