Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 1e2e51fa rédigé par Théo LE BAIL's avatar Théo LE BAIL
Parcourir les fichiers

keep user connected

parent 56794235
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!40identification admin et methodes hash
......@@ -43,7 +43,14 @@ module.exports = (passport) => {
})(req, res, next);
});
app.get('/check-auth', (req, res) => {
console.log(req.user);
if (req.user) {
res.json({ isAuthenticated: true, user: req.user });
} else {
res.json({ isAuthenticated: false });
}
});
......
......@@ -74,9 +74,21 @@ const loadPartials = (() => {
}
})();
page('/listecourse', async function () {
async function isAuthenticated() {
const requestConnect = await fetch('/api/check-auth');
const reponseJson = await requestConnect.json();
context.logged = reponseJson.isAuthenticated;
context.user = reponseJson.user;
if (!context.logged) {
page('/login');
return false;
}
return true;
}
page('/listecourse', async function () {
if (!(await isAuthenticated())) {
return;
}
......@@ -184,12 +196,10 @@ page('/login', async function () {
});
page('/inventaire', async function (request) {
if (!context.logged) {
page('/login');
if (!(await isAuthenticated())) {
return;
}
updateHeaderContext(context, "inventaire");
let response = await fetch('api/inventaire');
......@@ -241,11 +251,9 @@ page('/inventaire', async function (request) {
page('/fournisseurs', async function (request) {
if (!context.logged) {
page('/login');
if (!(await isAuthenticated())) {
return;
}
updateHeaderContext(context, "fournisseurs");
// fonction interne de chargement et d'affichage des albums d'un artiste
context.fournisseurs = await (await fetch('api/fournique')).json();
......@@ -281,22 +289,18 @@ page('/fournisseurs', async function (request) {
});
page('/options', async function () {
if (!context.logged) {
page('/login');
if (!(await isAuthenticated())) {
return;
}
updateHeaderContext(context, "options");
await renderTemplate(templates('public/page/options.mustache'), context);
});
// Route pour la page principale (index.html)
page('/', async function () {
if (!context.logged) {
page('/login');
if (!(await isAuthenticated())) {
return;
}
let response = await fetch('api/inventaire');
const produits = await response.json();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter