diff --git a/web/src/app/chat/ChatPage.tsx b/web/src/app/chat/ChatPage.tsx index 91cc559c5..8d9f5f6dd 100644 --- a/web/src/app/chat/ChatPage.tsx +++ b/web/src/app/chat/ChatPage.tsx @@ -63,7 +63,7 @@ export default async function ChatPage({ } catch (e) { console.log(`Some fetch failed for the main search page - ${e}`); } - const authTypeMetadata = results[0] as AuthTypeMetadata; + const authTypeMetadata = results[0] as AuthTypeMetadata | null; const user = results[1] as User | null; const connectorsResponse = results[2] as Response | null; const documentSetsResponse = results[3] as Response | null; @@ -71,12 +71,12 @@ export default async function ChatPage({ const chatSessionsResponse = results[5] as Response | null; const chatSessionMessagesResponse = results[6] as Response | null; - const authDisabled = authTypeMetadata.authType === "disabled"; + const authDisabled = authTypeMetadata?.authType === "disabled"; if (!authDisabled && !user) { return redirect("/auth/login"); } - if (user && !user.is_verified && authTypeMetadata.requiresVerification) { + if (user && !user.is_verified && authTypeMetadata?.requiresVerification) { return redirect("/auth/waiting-on-verification"); } diff --git a/web/src/app/search/page.tsx b/web/src/app/search/page.tsx index d6bd8a1f9..4a0112080 100644 --- a/web/src/app/search/page.tsx +++ b/web/src/app/search/page.tsx @@ -40,24 +40,25 @@ export default async function Home() { null, null, null, + null, ]; try { results = await Promise.all(tasks); } catch (e) { console.log(`Some fetch failed for the main search page - ${e}`); } - const authTypeMetadata = results[0] as AuthTypeMetadata; + const authTypeMetadata = results[0] as AuthTypeMetadata | null; const user = results[1] as User | null; const connectorsResponse = results[2] as Response | null; const documentSetsResponse = results[3] as Response | null; const personaResponse = results[4] as Response | null; - const authDisabled = authTypeMetadata.authType === "disabled"; + const authDisabled = authTypeMetadata?.authType === "disabled"; if (!authDisabled && !user) { return redirect("/auth/login"); } - if (user && !user.is_verified && authTypeMetadata.requiresVerification) { + if (user && !user.is_verified && authTypeMetadata?.requiresVerification) { return redirect("/auth/waiting-on-verification"); } diff --git a/web/src/components/admin/Layout.tsx b/web/src/components/admin/Layout.tsx index 32fc02bbd..10a6408c3 100644 --- a/web/src/components/admin/Layout.tsx +++ b/web/src/components/admin/Layout.tsx @@ -11,15 +11,32 @@ import { RobotIcon, ConnectorIcon, } from "@/components/icons/icons"; -import { getAuthDisabledSS, getCurrentUserSS } from "@/lib/userSS"; +import { User } from "@/lib/types"; +import { + AuthTypeMetadata, + getAuthTypeMetadataSS, + getCurrentUserSS, +} from "@/lib/userSS"; import { redirect } from "next/navigation"; export async function Layout({ children }: { children: React.ReactNode }) { - const [authDisabled, user] = await Promise.all([ - getAuthDisabledSS(), - getCurrentUserSS(), - ]); + const tasks = [getAuthTypeMetadataSS(), getCurrentUserSS()]; + // catch cases where the backend is completely unreachable here + // without try / catch, will just raise an exception and the page + // will not render + let results: (User | AuthTypeMetadata | null)[] = [null, null]; + try { + results = await Promise.all(tasks); + } catch (e) { + console.log(`Some fetch failed for the main search page - ${e}`); + } + + const authTypeMetadata = results[0] as AuthTypeMetadata | null; + const user = results[1] as User | null; + + const authDisabled = authTypeMetadata?.authType === "disabled"; + const requiresVerification = authTypeMetadata?.requiresVerification; if (!authDisabled) { if (!user) { return redirect("/auth/login"); @@ -27,6 +44,9 @@ export async function Layout({ children }: { children: React.ReactNode }) { if (user.role !== "admin") { return redirect("/"); } + if (!user.is_verified && requiresVerification) { + return redirect("/auth/waiting-on-verification"); + } } return (