From fdb65366d785d40c0b8783496687d3045d93770b Mon Sep 17 00:00:00 2001
From: Marco Beretta <81851188+Berry-13@users.noreply.github.com>
Date: Wed, 6 Dec 2023 13:08:49 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A7=20feat:=20disable=20login=20(ALLOW?=
=?UTF-8?q?=5FEMAIL=5FLOGIN)=20(#1282)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* added ALLOW_EMAIL_LOGIN
* update .env.example
* fix(config) email login true by default
* Update dotenv.md
---
.env.example | 1 +
api/server/routes/__tests__/config.spec.js | 1 +
api/server/routes/config.js | 3 +++
client/src/components/Auth/Login.tsx | 4 ++--
client/src/components/Auth/__tests__/Login.spec.tsx | 1 +
client/src/components/Auth/__tests__/Registration.spec.tsx | 1 +
docs/install/dotenv.md | 5 ++++-
packages/data-provider/src/types.ts | 1 +
8 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/.env.example b/.env.example
index 0869b28a1..8646f775b 100644
--- a/.env.example
+++ b/.env.example
@@ -214,6 +214,7 @@ CHECK_BALANCE=false
# Registration and Login #
#========================#
+ALLOW_EMAIL_LOGIN=true
ALLOW_REGISTRATION=true
ALLOW_SOCIAL_LOGIN=false
ALLOW_SOCIAL_REGISTRATION=false
diff --git a/api/server/routes/__tests__/config.spec.js b/api/server/routes/__tests__/config.spec.js
index 9194d458f..4833b83d1 100644
--- a/api/server/routes/__tests__/config.spec.js
+++ b/api/server/routes/__tests__/config.spec.js
@@ -62,6 +62,7 @@ describe.skip('GET /', () => {
githubLoginEnabled: true,
discordLoginEnabled: true,
serverDomain: 'http://test-server.com',
+ emailLoginEnabled: 'true',
registrationEnabled: 'true',
socialLoginEnabled: 'true',
});
diff --git a/api/server/routes/config.js b/api/server/routes/config.js
index c18d35541..9c02aa53f 100644
--- a/api/server/routes/config.js
+++ b/api/server/routes/config.js
@@ -1,6 +1,8 @@
const express = require('express');
const router = express.Router();
const { isEnabled } = require('../utils');
+const emailLoginEnabled =
+ process.env.ALLOW_EMAIL_LOGIN === undefined || isEnabled(process.env.ALLOW_EMAIL_LOGIN);
router.get('/', async function (req, res) {
try {
@@ -19,6 +21,7 @@ router.get('/', async function (req, res) {
githubLoginEnabled: !!process.env.GITHUB_CLIENT_ID && !!process.env.GITHUB_CLIENT_SECRET,
discordLoginEnabled: !!process.env.DISCORD_CLIENT_ID && !!process.env.DISCORD_CLIENT_SECRET,
serverDomain: process.env.DOMAIN_SERVER || 'http://localhost:3080',
+ emailLoginEnabled,
registrationEnabled: isEnabled(process.env.ALLOW_REGISTRATION),
socialLoginEnabled: isEnabled(process.env.ALLOW_SOCIAL_LOGIN),
emailEnabled:
diff --git a/client/src/components/Auth/Login.tsx b/client/src/components/Auth/Login.tsx
index c307a2490..6cb06e428 100644
--- a/client/src/components/Auth/Login.tsx
+++ b/client/src/components/Auth/Login.tsx
@@ -34,7 +34,7 @@ function Login() {
{localize(getLoginError(error))}
)}
-
{' '} @@ -44,7 +44,7 @@ function Login() {
)} - {startupConfig?.socialLoginEnabled && ( + {startupConfig?.socialLoginEnabled && startupConfig?.emailLoginEnabled && ( <>