I'm working on building an node/express backend and continue to receive the following error: (node:35061) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. I'm not exactly sure what i am doing wrong here... Can someone educate me on what the issue might be? TIA!
Route
userRoutes.post('', async (req, res) => {
try {
const { email, password } = req.body;
const validate = await signUp.validate({ email, password });
res.send(validate);
const newUser = new User({ email, password });
const sessionUser = sessionizeUser(newUser);
await newUser.save();
req.session.user = sessionUser;
res.send(sessionUser);
return;
} catch (error) {
res.status(400).send(parseError(error));
}
});