implemented a simple backend for mobile banking

This commit is contained in:
2025-06-02 13:24:10 +05:30
commit c350c591f6
26 changed files with 4060 additions and 0 deletions

17
src/util/hash.js Normal file
View File

@@ -0,0 +1,17 @@
const bcrypt = require('bcrypt');
const { logger } = require('./logger');
async function hashPassword(password) {
return await bcrypt.hash(password, 10);
}
async function comparePassword(plain, hash) {
const hashedPassword = await hashPassword(plain);
logger.info(hashedPassword, 'passed password after hashing');
return await bcrypt.compare(plain, hash);
}
module.exports = {
hashPassword,
comparePassword,
};

15
src/util/jwt.js Normal file
View File

@@ -0,0 +1,15 @@
const jwt = require('jsonwebtoken');
const { jwtSecret } = require('../config/config');
function generateToken(payload, expiresIn = '1h') {
return jwt.sign({ payload }, jwtSecret, { expiresIn });
}
function verifyToken(token) {
return jwt.verify(token, jwtSecret);
}
module.exports = {
generateToken,
verifyToken,
};

22
src/util/logger.js Normal file
View File

@@ -0,0 +1,22 @@
const pino = require('pino');
const isDev = process.env.NODE_ENV !== 'production';
const logger = pino({
transport: isDev
? {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:standard',
ignore: 'pid,hostname',
},
}
: undefined,
level: isDev ? 'debug' : 'info',
});
const requestLogger = (req, _res, next) => {
logger.info(`${req.method} ${req.url}`);
next();
};
module.exports = { logger, requestLogger };