remove jwtSecret from settings
This commit is contained in:
1 parent
6418efde2a
commit
6268b2573c
7 files changed
+47
-34
No files matched your search
+1
-1
@@ -53,7 +53,7 @@ function App() {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getAppSettings(authToken));
|
dispatch(getAppSettings({ authToken }));
|
||||||
}, [dispatch, authToken]);
|
}, [dispatch, authToken]);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
|||||||
@@ -5,26 +5,14 @@ const initialState = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
apiBaseUrl: "http://localhost:5000/api/v1",
|
apiBaseUrl: "http://localhost:5000/api/v1",
|
||||||
logLevel: "debug",
|
logLevel: "debug",
|
||||||
clientHost: "http://localhost:5173",
|
|
||||||
jwtSecret: "my_secret",
|
|
||||||
dbType: "MongoDB",
|
|
||||||
dbConnectionString: "mongodb://localhost:27017/uptime_db",
|
|
||||||
redisHost: "127.0.0.1",
|
|
||||||
redisPort: 6379,
|
|
||||||
jwtTTL: "99d",
|
|
||||||
pagespeedApiKey: "",
|
|
||||||
systemEmailHost: "smtp.gmail.com",
|
|
||||||
systemEmailPort: 465,
|
|
||||||
systemEmailAddress: "",
|
|
||||||
systemEmailPassword: "",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAppSettings = createAsyncThunk(
|
export const getAppSettings = createAsyncThunk(
|
||||||
"settings/getSettings",
|
"settings/getSettings",
|
||||||
async (authToken, thunkApi) => {
|
async (data, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const res = await networkService.getAppSettings({
|
const res = await networkService.getAppSettings({
|
||||||
authToken: authToken,
|
authToken: data.authToken,
|
||||||
});
|
});
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -83,7 +71,8 @@ const handleGetSettingsFulfilled = (state, action) => {
|
|||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
state.success = action.payload.success;
|
state.success = action.payload.success;
|
||||||
state.msg = action.payload.msg;
|
state.msg = action.payload.msg;
|
||||||
Object.assign(state, action.payload.data);
|
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
||||||
|
state.logLevel = action.payload.data.logLevel;
|
||||||
};
|
};
|
||||||
const handleGetSettingsRejected = (state, action) => {
|
const handleGetSettingsRejected = (state, action) => {
|
||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
@@ -94,7 +83,8 @@ const handleUpdateSettingsFulfilled = (state, action) => {
|
|||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
state.success = action.payload.success;
|
state.success = action.payload.success;
|
||||||
state.msg = action.payload.msg;
|
state.msg = action.payload.msg;
|
||||||
Object.assign(state, action.payload.data);
|
state.apiBaseUrl = action.payload.data.apiBaseUrl;
|
||||||
|
state.logLevel = action.payload.data.logLevel;
|
||||||
};
|
};
|
||||||
const handleUpdateSettingsRejected = (state, action) => {
|
const handleUpdateSettingsRejected = (state, action) => {
|
||||||
state.isLoading = false;
|
state.isLoading = false;
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import PropTypes from "prop-types";
|
|||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import { ConfigBox } from "../Settings/styled";
|
import { ConfigBox } from "../Settings/styled";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { updateAppSettings } from "../../Features/Settings/settingsSlice";
|
import {
|
||||||
|
getAppSettings,
|
||||||
|
updateAppSettings,
|
||||||
|
} from "../../Features/Settings/settingsSlice";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import Select from "../../Components/Inputs/Select";
|
||||||
|
|
||||||
@@ -26,7 +29,33 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const settings = useSelector((state) => state.settings);
|
const settings = useSelector((state) => state.settings);
|
||||||
const [localSettings, setLocalSettings] = useState(settings);
|
const [localSettings, setLocalSettings] = useState({
|
||||||
|
apiBaseUrl: "",
|
||||||
|
logLevel: "debug",
|
||||||
|
systemEmailHost: "",
|
||||||
|
systemEmailPort: "",
|
||||||
|
systemEmailAddress: "",
|
||||||
|
systemEmailPassword: "",
|
||||||
|
jwtTTL: "",
|
||||||
|
dbType: "",
|
||||||
|
redisHost: "",
|
||||||
|
redisPort: "",
|
||||||
|
pagespeedApiKey: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getSettings = async () => {
|
||||||
|
const action = await dispatch(getAppSettings({ authToken }));
|
||||||
|
if (action.payload.success) {
|
||||||
|
console.log(action.payload.data);
|
||||||
|
setLocalSettings(action.payload.data);
|
||||||
|
} else {
|
||||||
|
createToast({ body: "Failed to get settings" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getSettings();
|
||||||
|
}, [authToken, dispatch]);
|
||||||
|
|
||||||
const logItems = [
|
const logItems = [
|
||||||
{ _id: 1, name: "none" },
|
{ _id: 1, name: "none" },
|
||||||
{ _id: 2, name: "debug" },
|
{ _id: 2, name: "debug" },
|
||||||
@@ -58,6 +87,8 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
);
|
);
|
||||||
let body = "";
|
let body = "";
|
||||||
if (action.payload.success) {
|
if (action.payload.success) {
|
||||||
|
console.log(action.payload.data);
|
||||||
|
setLocalSettings(action.payload.data);
|
||||||
body = "Settings saved successfully";
|
body = "Settings saved successfully";
|
||||||
} else {
|
} else {
|
||||||
body = "Failed to save settings";
|
body = "Failed to save settings";
|
||||||
@@ -153,14 +184,6 @@ const AdvancedSettings = ({ isAdmin }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.spacing(20)}>
|
<Stack gap={theme.spacing(20)}>
|
||||||
<Field
|
|
||||||
type="text"
|
|
||||||
id="jwtSecret"
|
|
||||||
label="JWT Secret"
|
|
||||||
name="jwtSecret"
|
|
||||||
value={localSettings.jwtSecret}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
<Field
|
<Field
|
||||||
type="text"
|
type="text"
|
||||||
id="jwtTTL"
|
id="jwtTTL"
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ const { updateAppSettingsBodyValidation } = require("../validation/joi");
|
|||||||
|
|
||||||
const getAppSettings = async (req, res, next) => {
|
const getAppSettings = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const settings = await req.settingsService.getSettings();
|
const settings = { ...(await req.settingsService.getSettings()) };
|
||||||
|
delete settings.jwtSecret;
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.GET_APP_SETTINGS,
|
msg: successMessages.GET_APP_SETTINGS,
|
||||||
@@ -31,7 +32,8 @@ const updateAppSettings = async (req, res, next) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await req.db.updateAppSettings(req.body);
|
await req.db.updateAppSettings(req.body);
|
||||||
const updatedSettings = await req.settingsService.reloadSettings();
|
const updatedSettings = { ...(await req.settingsService.reloadSettings()) };
|
||||||
|
delete updatedSettings.jwtSecret;
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: successMessages.UPDATE_APP_SETTINGS,
|
msg: successMessages.UPDATE_APP_SETTINGS,
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ const verifyJWT = (req, res, next) => {
|
|||||||
const parsedToken = token.slice(TOKEN_PREFIX.length, token.length);
|
const parsedToken = token.slice(TOKEN_PREFIX.length, token.length);
|
||||||
// Verify the token's authenticity
|
// Verify the token's authenticity
|
||||||
const { jwtSecret } = req.settingsService.getSettings();
|
const { jwtSecret } = req.settingsService.getSettings();
|
||||||
|
|
||||||
jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
|
jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ const { env } = require("process");
|
|||||||
const AppSettings = require("../models/AppSettings");
|
const AppSettings = require("../models/AppSettings");
|
||||||
const SERVICE_NAME = "SettingsService";
|
const SERVICE_NAME = "SettingsService";
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
|
logLevel: undefined,
|
||||||
|
apiBaseUrl: undefined,
|
||||||
clientHost: process.env.CLIENT_HOST,
|
clientHost: process.env.CLIENT_HOST,
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
dbType: process.env.DB_TYPE,
|
dbType: process.env.DB_TYPE,
|
||||||
@@ -18,7 +20,7 @@ const envConfig = {
|
|||||||
|
|
||||||
class SettingsService {
|
class SettingsService {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.settings = envConfig;
|
this.settings = { ...envConfig };
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
@@ -27,7 +29,6 @@ class SettingsService {
|
|||||||
if (!this.settings) {
|
if (!this.settings) {
|
||||||
throw new Error("Settings not found");
|
throw new Error("Settings not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to load settings from env first, if not found, load from db
|
// Try to load settings from env first, if not found, load from db
|
||||||
for (const key in envConfig) {
|
for (const key in envConfig) {
|
||||||
if (envConfig[key] === undefined && dbSettings[key] !== undefined) {
|
if (envConfig[key] === undefined && dbSettings[key] !== undefined) {
|
||||||
@@ -38,7 +39,6 @@ class SettingsService {
|
|||||||
if (!this.settings) {
|
if (!this.settings) {
|
||||||
throw new Error("Settings not found");
|
throw new Error("Settings not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.settings;
|
return this.settings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||||
|
|||||||
@@ -389,7 +389,6 @@ const updateAppSettingsBodyValidation = joi.object({
|
|||||||
apiBaseUrl: joi.string().allow(""),
|
apiBaseUrl: joi.string().allow(""),
|
||||||
logLevel: joi.string().valid("debug", "none", "error", "warn").allow(""),
|
logLevel: joi.string().valid("debug", "none", "error", "warn").allow(""),
|
||||||
clientHost: joi.string().allow(""),
|
clientHost: joi.string().allow(""),
|
||||||
jwtSecret: joi.string().allow(""),
|
|
||||||
dbType: joi.string().allow(""),
|
dbType: joi.string().allow(""),
|
||||||
dbConnectionString: joi.string().allow(""),
|
dbConnectionString: joi.string().allow(""),
|
||||||
redisHost: joi.string().allow(""),
|
redisHost: joi.string().allow(""),
|
||||||
|
|||||||
Reference in new issue
Block a user