diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index cd9284479..8d41f916b 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -18,6 +18,7 @@ const { errorMessages, successMessages } = require("../utils/messages"); var jwt = require("jsonwebtoken"); const SERVICE_NAME = "AuthController"; const { getTokenFromHeaders } = require("../utils/utils"); +const crypto = require("crypto"); /** * Creates and returns JWT token with an arbitrary payload @@ -61,7 +62,12 @@ const registerController = async (req, res, next) => { const superAdminExists = await req.db.checkSuperadmin(req, res); if (superAdminExists) { await req.db.getInviteTokenAndDelete(inviteToken); + } else { + // This is the first account, create JWT secret to use if one is not supplied by env + const jwtSecret = crypto.randomBytes(64).toString("hex"); + await req.db.updateAppSettings({ jwtSecret }); } + const newUser = await req.db.insertUser({ ...req.body }, req.file); logger.info(successMessages.AUTH_CREATE_USER, { service: SERVICE_NAME, diff --git a/Server/controllers/settingsController.js b/Server/controllers/settingsController.js index 77895caea..e3444436b 100644 --- a/Server/controllers/settingsController.js +++ b/Server/controllers/settingsController.js @@ -4,7 +4,7 @@ const { updateAppSettingsBodyValidation } = require("../validation/joi"); const getAppSettings = async (req, res, next) => { try { - const settings = await req.db.getAppSettings(); + const settings = await req.settingsService.getSettings(); return res.status(200).json({ success: true, msg: successMessages.GET_APP_SETTINGS, @@ -30,7 +30,7 @@ const updateAppSettings = async (req, res, next) => { } try { - const settings = await req.db.updateAppSettings(req.body); + await req.db.updateAppSettings(req.body); const updatedSettings = await req.settingsService.reloadSettings(); return res.status(200).json({ success: true,