From 1a327e9f269bfff87c65b01878ace384bfaa4561 Mon Sep 17 00:00:00 2001 From: SchadenKai Date: Wed, 2 Oct 2024 08:50:52 +0800 Subject: [PATCH 1/3] feat: add two factor auth to feature flags in the frontend --- backend/enmedd/server/feature_flags/models.py | 1 + web/src/app/admin/settings/interfaces.ts | 1 + web/src/app/auth/login/LoginForms.tsx | 26 ++++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/backend/enmedd/server/feature_flags/models.py b/backend/enmedd/server/feature_flags/models.py index aa650177e08..83b5e743bd3 100644 --- a/backend/enmedd/server/feature_flags/models.py +++ b/backend/enmedd/server/feature_flags/models.py @@ -11,6 +11,7 @@ class FeatureFlags(BaseModel): whitelabelling: bool = True share_chat: bool = False explore_assistants: bool = False + two_factor_auth: bool = True def check_validity(self) -> None: return diff --git a/web/src/app/admin/settings/interfaces.ts b/web/src/app/admin/settings/interfaces.ts index f45ac1b97c1..5d26537db3f 100644 --- a/web/src/app/admin/settings/interfaces.ts +++ b/web/src/app/admin/settings/interfaces.ts @@ -23,6 +23,7 @@ export interface FeatureFlags { whitelabelling: boolean; share_chat: boolean; explore_assistants: boolean; + two_factor_auth: boolean; } export interface CombinedSettings { diff --git a/web/src/app/auth/login/LoginForms.tsx b/web/src/app/auth/login/LoginForms.tsx index b47e1b92865..5159b6307f9 100644 --- a/web/src/app/auth/login/LoginForms.tsx +++ b/web/src/app/auth/login/LoginForms.tsx @@ -5,7 +5,7 @@ import { basicLogin, basicSignup } from "@/lib/user"; import { Form, Formik } from "formik"; import { useRouter } from "next/navigation"; import * as Yup from "yup"; -import { useState } from "react"; +import { useContext, useState } from "react"; import { Spinner } from "@/components/Spinner"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; @@ -16,11 +16,13 @@ import GmailIcon from "../../../../public/Gmail.png"; import MicrosoftIcon from "../../../../public/microsoft.svg"; import Image from "next/image"; import Link from "next/link"; +import { SettingsContext } from "@/components/settings/SettingsProvider"; export function LogInForms({}: {}) { const router = useRouter(); const { toast } = useToast(); const [isLoading, setIsLoading] = useState(false); + const settings = useContext(SettingsContext); return ( <> @@ -39,14 +41,20 @@ export function LogInForms({}: {}) { const loginResponse = await basicLogin(values.email, values.password); if (loginResponse.ok) { - router.push(`/auth/2factorverification/?email=${values.email}`); - await fetch("/api/users/generate-otp", { - method: "PATCH", - headers: { - "Content-Type": "application/json", - }, - credentials: "include", - }); + console.log(JSON.stringify(settings?.featureFlags)); + if (settings?.featureFlags.two_factor_auth == true) { + console.log("This has been activated"); + router.push(`/auth/2factorverification/?email=${values.email}`); + await fetch("/api/users/generate-otp", { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + }); + } else { + router.push("/"); + } } else { setIsLoading(false); const errorDetail = (await loginResponse.json()).detail; From 348060afc4368a79fdca3fceaeef4af5fa0dfe1b Mon Sep 17 00:00:00 2001 From: SchadenKai Date: Wed, 2 Oct 2024 08:52:58 +0800 Subject: [PATCH 2/3] chore: cleaned out code --- web/src/app/auth/login/LoginForms.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/web/src/app/auth/login/LoginForms.tsx b/web/src/app/auth/login/LoginForms.tsx index 5159b6307f9..18ff0636136 100644 --- a/web/src/app/auth/login/LoginForms.tsx +++ b/web/src/app/auth/login/LoginForms.tsx @@ -43,7 +43,6 @@ export function LogInForms({}: {}) { if (loginResponse.ok) { console.log(JSON.stringify(settings?.featureFlags)); if (settings?.featureFlags.two_factor_auth == true) { - console.log("This has been activated"); router.push(`/auth/2factorverification/?email=${values.email}`); await fetch("/api/users/generate-otp", { method: "PATCH", From 5ad8d7c4cc3579cc1a625e28dd6d2ae8f4f3fa46 Mon Sep 17 00:00:00 2001 From: SchadenKai Date: Wed, 2 Oct 2024 08:53:35 +0800 Subject: [PATCH 3/3] chore: cleaned out code --- web/src/app/auth/login/LoginForms.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/src/app/auth/login/LoginForms.tsx b/web/src/app/auth/login/LoginForms.tsx index 5159b6307f9..432d4b12579 100644 --- a/web/src/app/auth/login/LoginForms.tsx +++ b/web/src/app/auth/login/LoginForms.tsx @@ -41,9 +41,7 @@ export function LogInForms({}: {}) { const loginResponse = await basicLogin(values.email, values.password); if (loginResponse.ok) { - console.log(JSON.stringify(settings?.featureFlags)); if (settings?.featureFlags.two_factor_auth == true) { - console.log("This has been activated"); router.push(`/auth/2factorverification/?email=${values.email}`); await fetch("/api/users/generate-otp", { method: "PATCH",