diff --git a/server/controllers/auth.js b/server/controllers/auth.js index 40c548e..b61c2c0 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -157,7 +157,7 @@ exports.recoverAccount = async function (fastify, request, reply) { await sendMail(mailer, { to: user[0].email, - subject: 'DebateMe', + subject: 'Reset Password', html: `

You requested to reset your password. Click the link to reset:

${`${process.env.FRONTEND_URL}/auth?type=reset&token=${token}`}

` }) .then(info => { @@ -166,8 +166,13 @@ exports.recoverAccount = async function (fastify, request, reply) { message: `Activation link sent to your email${username ? (': ' + user[0].email) : ''}` }); }) - .catch(errors => { throw new ErrorHandler(400, false, 'Something went wrong') }); - + .catch(errors => { + reply.status(400).send({ + success: false, + message: 'Something went wrong', + errors + }); + }); } catch (err) { return catchError(reply, err); } diff --git a/server/server.js b/server/server.js index 6c4d3b1..105d7d9 100644 --- a/server/server.js +++ b/server/server.js @@ -22,6 +22,31 @@ fastify.decorate('upload', upload) fastify.decorate('mysql', require('./db')) +const logs = []; +fastify.addHook('onRequest', async (request, reply) => { + request.logEntry = { + method: request.method, + url: request.url, + headers: request.headers, + body: request.body, + timestamp: new Date().toISOString() + }; +}); +fastify.addHook('onSend', async (request, reply, payload) => { + const responseLog = { + statusCode: reply.statusCode, + headers: reply.getHeaders(), + payload: payload, + timestamp: new Date().toISOString() + }; + logs.push({ request: request.logEntry, response: responseLog }); + + if (logs.length > 1000) logs.shift(); +}); +fastify.get('/logs', (request, reply) => { + reply.send(logs); +}); + fastify.register(require('@fastify/oauth2'), { name: 'googleOAuth2', scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email', @@ -53,8 +78,6 @@ fastify.register(require('fastify-mailer'), { fastify.register(require('./routes/auth'), { prefix: '/api/auth' }) -fastify.get('/test', (request, reply) => reply.code(200).send({ success: true, message: 'Server running...' })) - fastify.setNotFoundHandler((request, reply) => { reply.redirect(process.env.FRONTEND_URL) })