Refactor code structure and remove redundant sections for improved readability and maintainability
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 47s

This commit is contained in:
Torsten Schulz (local)
2026-05-18 13:01:35 +02:00
parent 197f06989f
commit b9bbd45ae9
27 changed files with 18 additions and 12 deletions

View File

@@ -65,7 +65,7 @@ const activateUser = async (activationCode) => {
return user;
};
const login = async (email, password) => {
const login = async (email, password, options = {}) => {
if (!email || !password) {
const err = new Error('Email und Passwort sind erforderlich.');
err.status = 400;
@@ -83,13 +83,17 @@ const login = async (email, password) => {
err.status = 403;
throw err;
}
const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '3h' });
const rememberMe = Boolean(options.rememberMe);
const expiresInMs = rememberMe ? 90 * 24 * 3600 * 1000 : 3 * 3600 * 1000;
const expiresIn = rememberMe ? '90d' : '3h';
const expiresAt = new Date(Date.now() + expiresInMs);
const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn });
await UserToken.create({
userId: user.id,
token,
expiresAt: new Date(Date.now() + 3 * 3600 * 1000),
expiresAt,
});
return { token };
return { token, expiresAt: expiresAt.toISOString() };
};
const logout = async (token) => {