mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
beautified
This commit is contained in:
@ -22,4 +22,4 @@ const knexInstance = require('knex')({
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = knexInstance;
|
||||
module.exports = knexInstance;
|
@ -13,7 +13,7 @@
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
function generateToken (person_id) {
|
||||
function generateToken(person_id) {
|
||||
// The payload the JWT will carry within itself
|
||||
const payload = {
|
||||
person_id
|
||||
@ -26,16 +26,20 @@ function generateToken (person_id) {
|
||||
}
|
||||
|
||||
// Middlware
|
||||
function verifyToken (req, res, next) {
|
||||
function verifyToken(req, res, next) {
|
||||
const token = req.headers.authorization;
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).send({ error: 'No token provided' });
|
||||
return res.status(401).send({
|
||||
error: 'No token provided'
|
||||
});
|
||||
}
|
||||
|
||||
jwt.verify(token, process.env.JWT_SECRET_KEY, (err, decoded) => {
|
||||
if (err) {
|
||||
return res.status(401).send({ error: 'Failed to authenticate token' });
|
||||
return res.status(401).send({
|
||||
error: 'Failed to authenticate token'
|
||||
});
|
||||
}
|
||||
|
||||
// If the token is valid, store the decoded data in the request object
|
||||
@ -48,4 +52,4 @@ function verifyToken (req, res, next) {
|
||||
module.exports = {
|
||||
generateToken,
|
||||
verifyToken
|
||||
};
|
||||
};
|
@ -16,7 +16,7 @@
|
||||
* @param {*} email email to validate
|
||||
* @returns true or false
|
||||
*/
|
||||
function validateEmail (email) {
|
||||
function validateEmail(email) {
|
||||
const regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
|
||||
return regex.test(email);
|
||||
}
|
||||
@ -27,7 +27,7 @@ function validateEmail (email) {
|
||||
* @param {*} dateString the date to validate
|
||||
* @returns true or false
|
||||
*/
|
||||
function isPostgresDateFormatValid (dateString) {
|
||||
function isPostgresDateFormatValid(dateString) {
|
||||
const regex = /^\d{4}-\d{2}-\d{2}$/;
|
||||
return regex.test(dateString);
|
||||
}
|
||||
@ -35,4 +35,4 @@ function isPostgresDateFormatValid (dateString) {
|
||||
module.exports = {
|
||||
validateEmail,
|
||||
isPostgresDateFormatValid
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user