implement settings page and redirect to onboarding
This commit is contained in:
parent
88acbd6d54
commit
e219d07743
5 changed files with 134 additions and 50 deletions
|
|
@ -23,6 +23,7 @@ interface Settings {
|
|||
langflow_public_url?: string;
|
||||
agent?: AgentSettings;
|
||||
ingest?: IngestSettings;
|
||||
edited?: boolean;
|
||||
}
|
||||
|
||||
export const useGetSettingsQuery = (
|
||||
|
|
|
|||
|
|
@ -1,24 +1,39 @@
|
|||
"use client"
|
||||
"use client";
|
||||
|
||||
import { useEffect, Suspense } from "react"
|
||||
import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
import { Lock, LogIn, Loader2 } from "lucide-react"
|
||||
import { Loader2, Lock, LogIn } from "lucide-react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Suspense, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
import { useGetSettingsQuery } from "../api/queries/useGetSettingsQuery";
|
||||
|
||||
function LoginPageContent() {
|
||||
const { isLoading, isAuthenticated, isNoAuthMode, login } = useAuth()
|
||||
const router = useRouter()
|
||||
const searchParams = useSearchParams()
|
||||
const redirect = searchParams.get('redirect') || '/chat'
|
||||
const { isLoading, isAuthenticated, isNoAuthMode, login } = useAuth();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const { data: settings } = useGetSettingsQuery({
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
const redirect =
|
||||
settings && !settings.edited
|
||||
? "/onboarding"
|
||||
: searchParams.get("redirect") || "/chat";
|
||||
|
||||
// Redirect if already authenticated or in no-auth mode
|
||||
useEffect(() => {
|
||||
if (!isLoading && (isAuthenticated || isNoAuthMode)) {
|
||||
router.push(redirect)
|
||||
router.push(redirect);
|
||||
}
|
||||
}, [isLoading, isAuthenticated, isNoAuthMode, router, redirect])
|
||||
}, [isLoading, isAuthenticated, isNoAuthMode, router, redirect]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
|
|
@ -28,11 +43,11 @@ function LoginPageContent() {
|
|||
<p className="text-muted-foreground">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isAuthenticated || isNoAuthMode) {
|
||||
return null // Will redirect in useEffect
|
||||
return null; // Will redirect in useEffect
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -54,27 +69,29 @@ function LoginPageContent() {
|
|||
<LogIn className="h-4 w-4 mr-2" />
|
||||
Sign In with Google
|
||||
</Button>
|
||||
|
||||
|
||||
<p className="text-xs text-center text-muted-foreground">
|
||||
By signing in, you agree to our terms of service and privacy policy.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<Suspense fallback={
|
||||
<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>
|
||||
<Suspense
|
||||
fallback={
|
||||
<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>
|
||||
</div>
|
||||
}>
|
||||
}
|
||||
>
|
||||
<LoginPageContent />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
37
frontend/src/app/onboarding/page.tsx
Normal file
37
frontend/src/app/onboarding/page.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
"use client";
|
||||
|
||||
import { Suspense } from "react";
|
||||
import { useUpdateFlowSettingMutation } from "@/app/api/mutations/useUpdateFlowSettingMutation";
|
||||
import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";
|
||||
import { ProtectedRoute } from "@/components/protected-route";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
|
||||
function OnboardingPage() {
|
||||
const { isAuthenticated } = useAuth();
|
||||
// Fetch settings using React Query
|
||||
const { data: settings = {} } = useGetSettingsQuery({
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
// Mutations
|
||||
const updateFlowSettingMutation = useUpdateFlowSettingMutation({
|
||||
onSuccess: () => {
|
||||
console.log("Setting updated successfully");
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Failed to update setting:", error.message);
|
||||
},
|
||||
});
|
||||
|
||||
return <div className="space-y-8">Hello!</div>;
|
||||
}
|
||||
|
||||
export default function ProtectedOnboardingPage() {
|
||||
return (
|
||||
<ProtectedRoute>
|
||||
<Suspense fallback={<div>Loading onboarding...</div>}>
|
||||
<OnboardingPage />
|
||||
</Suspense>
|
||||
</ProtectedRoute>
|
||||
);
|
||||
}
|
||||
|
|
@ -21,12 +21,12 @@ export function LayoutWrapper({ children }: { children: React.ReactNode }) {
|
|||
const { selectedFilter, setSelectedFilter, isPanelOpen } =
|
||||
useKnowledgeFilter();
|
||||
const { isLoading, isAuthenticated } = useAuth();
|
||||
const { isLoading: isSettingsLoading } = useGetSettingsQuery({
|
||||
const { isLoading: isSettingsLoading, data: settings } = useGetSettingsQuery({
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
// List of paths that should not show navigation
|
||||
const authPaths = ["/login", "/auth/callback"];
|
||||
const authPaths = ["/login", "/auth/callback", "/onboarding"];
|
||||
const isAuthPage = authPaths.includes(pathname);
|
||||
|
||||
// Calculate active tasks for the bell icon
|
||||
|
|
@ -49,7 +49,7 @@ export function LayoutWrapper({ children }: { children: React.ReactNode }) {
|
|||
);
|
||||
}
|
||||
|
||||
if (isAuthPage) {
|
||||
if (isAuthPage || (settings && !settings.edited)) {
|
||||
// For auth pages, render without navigation
|
||||
return <div className="h-full">{children}</div>;
|
||||
}
|
||||
|
|
@ -68,7 +68,9 @@ export function LayoutWrapper({ children }: { children: React.ReactNode }) {
|
|||
viewBox="0 0 24 22"
|
||||
fill="currentColor"
|
||||
className="h-6 w-6 text-primary"
|
||||
aria-label="OpenRAG Logo"
|
||||
>
|
||||
<title>OpenRAG Logo</title>
|
||||
<path d="M13.0486 0.462158H9.75399C9.44371 0.462158 9.14614 0.586082 8.92674 0.806667L4.03751 5.72232C3.81811 5.9429 3.52054 6.06682 3.21026 6.06682H1.16992C0.511975 6.06682 -0.0165756 6.61212 0.000397655 7.2734L0.0515933 9.26798C0.0679586 9.90556 0.586745 10.4139 1.22111 10.4139H3.59097C3.90124 10.4139 4.19881 10.2899 4.41821 10.0694L9.34823 5.11269C9.56763 4.89211 9.8652 4.76818 10.1755 4.76818H13.0486C13.6947 4.76818 14.2185 4.24157 14.2185 3.59195V1.63839C14.2185 0.988773 13.6947 0.462158 13.0486 0.462158Z"></path>
|
||||
<path d="M19.5355 11.5862H22.8301C23.4762 11.5862 24 12.1128 24 12.7624V14.716C24 15.3656 23.4762 15.8922 22.8301 15.8922H19.957C19.6467 15.8922 19.3491 16.0161 19.1297 16.2367L14.1997 21.1934C13.9803 21.414 13.6827 21.5379 13.3725 21.5379H11.0026C10.3682 21.5379 9.84945 21.0296 9.83309 20.392L9.78189 18.3974C9.76492 17.7361 10.2935 17.1908 10.9514 17.1908H12.9918C13.302 17.1908 13.5996 17.0669 13.819 16.8463L18.7082 11.9307C18.9276 11.7101 19.2252 11.5862 19.5355 11.5862Z"></path>
|
||||
<path d="M19.5355 2.9796L22.8301 2.9796C23.4762 2.9796 24 3.50622 24 4.15583V6.1094C24 6.75901 23.4762 7.28563 22.8301 7.28563H19.957C19.6467 7.28563 19.3491 7.40955 19.1297 7.63014L14.1997 12.5868C13.9803 12.8074 13.6827 12.9313 13.3725 12.9313H10.493C10.1913 12.9313 9.90126 13.0485 9.68346 13.2583L4.14867 18.5917C3.93087 18.8016 3.64085 18.9187 3.33917 18.9187H1.32174C0.675616 18.9187 0.151832 18.3921 0.151832 17.7425V15.7343C0.151832 15.0846 0.675616 14.558 1.32174 14.558H3.32468C3.63496 14.558 3.93253 14.4341 4.15193 14.2135L9.40827 8.92878C9.62767 8.70819 9.92524 8.58427 10.2355 8.58427H12.9918C13.302 8.58427 13.5996 8.46034 13.819 8.23976L18.7082 3.32411C18.9276 3.10353 19.2252 2.9796 19.5355 2.9796Z"></path>
|
||||
|
|
|
|||
|
|
@ -1,33 +1,60 @@
|
|||
"use client"
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react"
|
||||
import { useRouter, usePathname } from "next/navigation"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
import { Loader2 } from "lucide-react"
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
import { useGetSettingsQuery } from "@/app/api/queries/useGetSettingsQuery";
|
||||
import { useAuth } from "@/contexts/auth-context";
|
||||
|
||||
interface ProtectedRouteProps {
|
||||
children: React.ReactNode
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
const { isLoading, isAuthenticated, isNoAuthMode } = useAuth()
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
|
||||
console.log("ProtectedRoute - isLoading:", isLoading, "isAuthenticated:", isAuthenticated, "isNoAuthMode:", isNoAuthMode, "pathname:", pathname)
|
||||
const { isLoading, isAuthenticated, isNoAuthMode } = useAuth();
|
||||
const { data: settings = {}, isLoading: isSettingsLoading } =
|
||||
useGetSettingsQuery({
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
console.log(
|
||||
"ProtectedRoute - isLoading:",
|
||||
isLoading,
|
||||
"isAuthenticated:",
|
||||
isAuthenticated,
|
||||
"isNoAuthMode:",
|
||||
isNoAuthMode,
|
||||
"pathname:",
|
||||
pathname,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// In no-auth mode, allow access without authentication
|
||||
if (isNoAuthMode) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!isLoading && !isAuthenticated) {
|
||||
// Redirect to login with current path as redirect parameter
|
||||
const redirectUrl = `/login?redirect=${encodeURIComponent(pathname)}`
|
||||
router.push(redirectUrl)
|
||||
const redirectUrl = `/login?redirect=${encodeURIComponent(pathname)}`;
|
||||
router.push(redirectUrl);
|
||||
return;
|
||||
}
|
||||
}, [isLoading, isAuthenticated, isNoAuthMode, router, pathname])
|
||||
|
||||
if (!isLoading && !isSettingsLoading && !settings.edited) {
|
||||
router.push("/onboarding");
|
||||
}
|
||||
}, [
|
||||
isLoading,
|
||||
isAuthenticated,
|
||||
isNoAuthMode,
|
||||
router,
|
||||
pathname,
|
||||
isSettingsLoading,
|
||||
settings.edited,
|
||||
]);
|
||||
|
||||
// Show loading state while checking authentication
|
||||
if (isLoading) {
|
||||
|
|
@ -38,19 +65,19 @@ export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
|||
<p className="text-muted-foreground">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// In no-auth mode, always render content
|
||||
if (isNoAuthMode) {
|
||||
return <>{children}</>
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
// Don't render anything if not authenticated (will redirect)
|
||||
if (!isAuthenticated) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
// Render protected content
|
||||
return <>{children}</>
|
||||
}
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue