Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

Add unauthorized page and IBM auth handling

Edwin Jose078d404240ff
diff --git a/frontend/app/unauthorized/page.tsx b/frontend/app/unauthorized/page.tsx
new file mode 100644
index 000000000..725cbd260
--- /dev/null
+++ b/frontend/app/unauthorized/page.tsx
@@ -0,0 +1,62 @@
+"use client";
+
+import { Loader2, ShieldAlert } from "lucide-react";
+import { useRouter } from "next/navigation";
+import { useEffect } from "react";
+import Logo from "@/components/icons/openrag-logo";
+import { useAuth } from "@/contexts/auth-context";
+
+export default function UnauthorizedPage() {
+ const { isLoading, isAuthenticated, isIbmAuthMode } = useAuth();
+ const router = useRouter();
+
+ useEffect(() => {
+ if (!isLoading && isAuthenticated) {
+ router.push("/chat");
+ }
+ }, [isLoading, isAuthenticated, router]);
+
+ if (isLoading) {
+ return (
+ <div className="min-h-screen flex items-center justify-center bg-background">
+ <div className="flex flex-col items-center gap-4">
+ <Loader2 className="h-8 w-8 animate-spin" />
+ <p className="text-muted-foreground">Loading...</p>
+ </div>
+ </div>
+ );
+ }
+
+ if (isAuthenticated) {
+ return null;
+ }
+
+ return (
+ <div className="min-h-dvh relative flex gap-4 flex-col items-center justify-center bg-card rounded-lg m-4">
+ <div className="flex flex-col items-center justify-center gap-6 z-10 max-w-md px-4 text-center">
+ <Logo className="fill-primary" width={50} height={40} />
+ <ShieldAlert className="h-12 w-12 text-destructive" />
+ <h1 className="text-2xl font-medium font-chivo">
+ Authentication Required
+ </h1>
+ {isIbmAuthMode ? (
+ <p className="text-muted-foreground">
+ Your session could not be authenticated. Please ensure you are
+ accessing OpenRAG through IBM watsonx.data with valid credentials.
+ </p>
+ ) : (
+ <p className="text-muted-foreground">
+ You do not have permission to access this page. Please sign in to
+ continue.
+ </p>
+ )}
+ <button
+ onClick={() => window.location.reload()}
+ className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90"
+ >
+ Retry
+ </button>
+ </div>
+ </div>
+ );
+}
diff --git a/frontend/components/protected-route.tsx b/frontend/components/protected-route.tsx
index 611513d5a..871d2bf5e 100644
--- a/frontend/components/protected-route.tsx
+++ b/frontend/components/protected-route.tsx
@@ -10,7 +10,7 @@ interface ProtectedRouteProps {
}
export function ProtectedRoute({ children }: ProtectedRouteProps) {
- const { isLoading, isAuthenticated, isNoAuthMode } = useAuth();
+ const { isLoading, isAuthenticated, isNoAuthMode, isIbmAuthMode } = useAuth();
const router = useRouter();
const pathname = usePathname();
@@ -21,20 +21,26 @@ export function ProtectedRoute({ children }: ProtectedRouteProps) {
isAuthenticated,
"isNoAuthMode:",
isNoAuthMode,
+ "isIbmAuthMode:",
+ isIbmAuthMode,
"pathname:",
pathname,
);
useEffect(() => {
- if (!isLoading && !isAuthenticated && !isNoAuthMode) {
- // Redirect to login with current path as redirect parameter
+ if (isLoading) return;
+
+ if (!isAuthenticated) {
+ if (isNoAuthMode) return;
+ if (isIbmAuthMode) {
+ router.push("/unauthorized");
+ return;
+ }
const redirectUrl = `/login?redirect=${encodeURIComponent(pathname)}`;
router.push(redirectUrl);
- return;
}
- }, [isLoading, isAuthenticated, isNoAuthMode, router, pathname]);
+ }, [isLoading, isAuthenticated, isNoAuthMode, isIbmAuthMode, router, pathname]);
- // Show loading state while checking authentication
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
@@ -46,16 +52,13 @@ export function ProtectedRoute({ children }: ProtectedRouteProps) {
);
}
- // In no-auth mode, always render content
if (isNoAuthMode) {
return <>{children}</>;
}
- // Don't render anything if not authenticated (will redirect)
if (!isAuthenticated) {
return null;
}
- // Render protected content
return <>{children}</>;
}