Set longer session times

This commit is contained in:
Dennis Postma 2024-07-21 23:30:11 +02:00
parent 6070e587c6
commit 792abdfaf6

View File

@ -63,14 +63,14 @@ async function addHttpRoutes(app: Application) {
try {
loginAccountSchema.parse({ username, password });
} catch (error: any) {
return res.status(400).json({ message: error.errors[0].message });
return res.status(400).json({ message: error.errors[0]?.message });
}
const userService = new UserService();
const user = await userService.login(username, password);
if (user) { //test
const token = jwt.sign({ id: user.id }, config.JWT_SECRET, { expiresIn: '1h' });
const token = jwt.sign({ id: user.id }, config.JWT_SECRET, { expiresIn: '4h' });
return res.status(200).json({ token });
}
@ -83,14 +83,14 @@ async function addHttpRoutes(app: Application) {
try {
registerAccountSchema.parse({ username, password });
} catch (error: any) {
return res.status(400).json({ message: error.errors[0].message });
return res.status(400).json({ message: error.errors[0]?.message });
}
const userService = new UserService();
const user = await userService.register(username, password);
if (user) {
const token = jwt.sign({ id: user.id }, config.JWT_SECRET, { expiresIn: '1h' });
const token = jwt.sign({ id: user.id }, config.JWT_SECRET, { expiresIn: '4h' });
return res.status(200).json({ token });
}