build: setup docker containers for development
This commit is contained in:
21
app/server/middlewares/authentication.js
Normal file
21
app/server/middlewares/authentication.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
const authenticateToken = function(req, res, next) {
|
||||
const token = req.cookies.auth_token;
|
||||
|
||||
if(!token) {
|
||||
res.redirect("/");
|
||||
}
|
||||
|
||||
const data = token.split('.');
|
||||
|
||||
const hash = crypto.createHmac('sha256', process.env.AUTH_JWT_SECRET).update(data[0] + '.' + data[1]).digest('base64url');
|
||||
|
||||
if (hash === data[2]) {
|
||||
next();
|
||||
} else {
|
||||
res.redirect('/users/login');
|
||||
}
|
||||
};
|
||||
|
||||
export default authenticateToken;
|
||||
12
app/server/middlewares/limitedUsers.js
Normal file
12
app/server/middlewares/limitedUsers.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import dbClient from '../db/index.js';
|
||||
|
||||
async function limitedUsers(_, res, next) {
|
||||
const countQuery = await dbClient.query('SELECT COUNT(*) FROM users');
|
||||
if(countQuery.rows[0].count > 0) {
|
||||
res.redirect('/users/login');
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
export default limitedUsers;
|
||||
Reference in New Issue
Block a user