mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* 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:
parent
fdc5265f48
commit
25211d6f23
16 changed files with 44356 additions and 44376 deletions
39
api/server/controllers/auth/LoginController.js
Normal file
39
api/server/controllers/auth/LoginController.js
Normal 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
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue