fix: 🐛 usage of new environment variables with Docker

This commit is contained in:
Ravinou 2024-08-17 21:27:17 +02:00
commit dd51c23aaf
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
5 changed files with 31 additions and 15 deletions

View file

@ -36,10 +36,10 @@ SSH_SERVER_PORT_LAN=
#DISABLE_DELETE_REPO=true
# Disable the integrations (API tokens to CRUD repositories)
#NEXT_PUBLIC_DISABLE_INTEGRATIONS=true
#DISABLE_INTEGRATIONS=true
# Hide the SSH port in the UI : quickcommands & wizard
#NEXT_PUBLIC_HIDE_SSH_PORT=true
#HIDE_SSH_PORT=true
# SMTP server settings
MAIL_SMTP_FROM=

View file

@ -1,7 +1,7 @@
//Lib
import 'react-toastify/dist/ReactToastify.css';
import classes from './UserSettings.module.css';
import { useState } from 'react';
import { useState, useEffect } from 'react';
//Components
import EmailSettings from './EmailSettings/EmailSettings';
@ -14,7 +14,25 @@ import Integrations from './Integrations/Integrations';
export default function UserSettings(props) {
//States
const [tab, setTab] = useState('General');
const DISABLE_INTEGRATIONS = process.env.NEXT_PUBLIC_DISABLE_INTEGRATIONS === 'true';
const [wizardEnv, setWizardEnv] = useState({});
//ComponentDidMount
useEffect(() => {
const fetchWizardEnv = async () => {
try {
const response = await fetch('/api/account/getWizardEnv', {
method: 'GET',
headers: {
'Content-type': 'application/json',
},
});
setWizardEnv((await response.json()).wizardEnv);
} catch (error) {
console.log('Fetching datas error');
}
};
fetchWizardEnv();
}, []);
return (
<div className={classes.containerSettings}>
@ -42,7 +60,7 @@ export default function UserSettings(props) {
>
Notifications
</button>
{!DISABLE_INTEGRATIONS && (
{wizardEnv.DISABLE_INTEGRATIONS !== 'true' && (
<button
className={tab === 'Integrations' ? classes.tabListButtonActive : classes.tabListButton}
onClick={() => setTab('Integrations')}

View file

@ -3,12 +3,10 @@ export default function lanCommandOption(wizardEnv, lanCommand) {
let SSH_SERVER_PORT;
if (lanCommand && wizardEnv.FQDN_LAN && wizardEnv.SSH_SERVER_PORT_LAN) {
FQDN = wizardEnv.FQDN_LAN;
SSH_SERVER_PORT =
process.env.NEXT_PUBLIC_HIDE_SSH_PORT === 'true' ? '' : ':' + wizardEnv.SSH_SERVER_PORT_LAN;
SSH_SERVER_PORT = wizardEnv.HIDE_SSH_PORT === 'true' ? '' : ':' + wizardEnv.SSH_SERVER_PORT_LAN;
} else {
FQDN = wizardEnv.FQDN;
SSH_SERVER_PORT =
process.env.NEXT_PUBLIC_HIDE_SSH_PORT === 'true' ? '' : ':' + wizardEnv.SSH_SERVER_PORT;
SSH_SERVER_PORT = wizardEnv.HIDE_SSH_PORT === 'true' ? '' : ':' + wizardEnv.SSH_SERVER_PORT;
}
return { FQDN, SSH_SERVER_PORT };

View file

@ -4,8 +4,7 @@ import path from 'path';
export default async function tokenController(API_KEY, FROM_IP) {
const jsonDirectory = path.join(process.cwd(), 'config');
try {
const DISABLE_INTEGRATIONS = process.env.NEXT_PUBLIC_DISABLE_INTEGRATIONS === 'true';
if (DISABLE_INTEGRATIONS) {
if (process.env.DISABLE_INTEGRATIONS === 'true') {
console.log('API auth failed from : ' + FROM_IP);
return null;
}

View file

@ -4,12 +4,13 @@ import { getServerSession } from 'next-auth/next';
export default async function handler(req, res) {
if (req.method == 'GET') {
//Verify that the user is logged in.
//AUTHENTICATION
const session = await getServerSession(req, res, authOptions);
if (!session) {
res.status(401).json({ message: 'You must be logged in.' });
return;
}
try {
function getEnvVariable(envName, defaultValue = '') {
return process.env[envName] || defaultValue;
@ -24,15 +25,15 @@ export default async function handler(req, res) {
SSH_SERVER_FINGERPRINT_RSA: getEnvVariable('SSH_SERVER_FINGERPRINT_RSA'),
SSH_SERVER_FINGERPRINT_ED25519: getEnvVariable('SSH_SERVER_FINGERPRINT_ED25519'),
SSH_SERVER_FINGERPRINT_ECDSA: getEnvVariable('SSH_SERVER_FINGERPRINT_ECDSA'),
HIDE_SSH_PORT: getEnvVariable('HIDE_SSH_PORT', 'false'),
DISABLE_INTEGRATIONS: getEnvVariable('DISABLE_INTEGRATIONS', 'false'),
};
res.status(200).json({ wizardEnv });
return;
} catch (error) {
//Log for backend
console.log(error);
//Log for frontend
res.status(500).json({
status: 500,
message: 'API error, contact the administrator',
});
return;