Skip to content
Snippets Groups Projects
Commit e09fd2d8 authored by Jesus Galaz Reyes's avatar Jesus Galaz Reyes
Browse files

Merge branch '13-enforce-user-authorization' into 'main'

Resolve "Enforce user authorization"

Closes #13

See merge request !7
parents db2c99de dbf57183
No related branches found
No related tags found
1 merge request!7Resolve "Enforce user authorization"
Pipeline #15735 passed
......@@ -6,6 +6,7 @@
<title>ToDo</title>
<link rel="stylesheet" href="./css/index.css" />
<script src="./js/index.js" defer></script>
<script src="./js/authorization.js" defer></script>
</head>
<body>
<div class="container">
......
// Obtener referencia a los elementos del DOM
// Get reference to DOM elements
const taskList = document.querySelector('.task-list ul');
const newTaskForm = document.querySelector('form');
......
document.addEventListener('DOMContentLoaded', async () => {
// Event for checking if the user is logged in
try {
const res = await fetch('/api/users/loggedin', { method: 'POST' });
if (!res.ok) {
window.location.href = 'login.html';
}
} catch (err) {
console.error('Error while checking if a user is logged in:', err);
}
});
\ No newline at end of file
......@@ -58,6 +58,17 @@ router.post('/login', async (req, res) => {
}
});
// Checking if the user is logged in
router.post('/loggedin', (req, res) => {
try {
if (!req.session.user) {
res.status(403).json({ error: 'Unauthorized' });
}
} catch (error) {
console.error('Authorization check failed:', error);
res.status(500).json({ error: 'Server error' });
}
});
// Closing user session
router.post('/logout', (req, res) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment