Skip to content

Commit

Permalink
Feat/feature-flags/add-new-features-to-feature-flags (#165)
Browse files Browse the repository at this point in the history
* feat: add two factor auth to feature flags in the frontend

* chore: cleaned out code

* chore: cleaned out code
  • Loading branch information
SchadenKai authored Oct 3, 2024
1 parent bca1c03 commit ce3ce2a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions backend/enmedd/server/feature_flags/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions web/src/app/admin/settings/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface FeatureFlags {
whitelabelling: boolean;
share_chat: boolean;
explore_assistants: boolean;
two_factor_auth: boolean;
}

export interface CombinedSettings {
Expand Down
24 changes: 15 additions & 9 deletions web/src/app/auth/login/LoginForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 (
<>
Expand All @@ -39,14 +41,18 @@ 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",
});
if (settings?.featureFlags.two_factor_auth == true) {
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;
Expand Down

0 comments on commit ce3ce2a

Please sign in to comment.