fix: #546 issue with closing registration (#547)

* fix: #546 issue with closing registration

* refactor: change casing of controller files for consistency

* fix: ensure registrationEnabled is sending a boolean value

* refactor: modifications to openId code
This commit is contained in:
Dan Orlando 2023-06-25 12:40:31 -07:00 committed by GitHub
parent fdc5265f48
commit 25211d6f23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 44356 additions and 44376 deletions

View file

@ -0,0 +1,39 @@
const User = require('../../../models/User');
const loginController = async (req, res) => {
try {
const user = await User.findById(
req.user._id
);
// If user doesn't exist, return error
if (!user) { // typeof user !== User) { // this doesn't seem to resolve the User type ??
return res.status(400).json({ message: 'Invalid credentials' });
}
const token = req.user.generateToken();
const expires = eval(process.env.SESSION_EXPIRY);
// Add token to cookie
res.cookie(
'token',
token,
{
expires: new Date(Date.now() + expires),
httpOnly: false,
secure: process.env.NODE_ENV === 'production'
}
);
return res.status(200).send({ token, user });
} catch (err) {
console.log(err);
}
// Generic error messages are safer
return res.status(500).json({ message: 'Something went wrong' });
};
module.exports = {
loginController
};