mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-06 13:09:39 +02:00
Add redirects for unauthenticated users
This commit is contained in:
parent
c68220103d
commit
b2cde3e4bb
@ -37,7 +37,7 @@ export default function Web() {
|
|||||||
|
|
||||||
const urlToLatestIndexAttempt = new Map<string, WebsiteIndexAttempt>();
|
const urlToLatestIndexAttempt = new Map<string, WebsiteIndexAttempt>();
|
||||||
const urlToLatestIndexSuccess = new Map<string, string>();
|
const urlToLatestIndexSuccess = new Map<string, string>();
|
||||||
data?.index_attempts.forEach((indexAttempt) => {
|
data?.index_attempts?.forEach((indexAttempt) => {
|
||||||
const latestIndexAttempt = urlToLatestIndexAttempt.get(indexAttempt.url);
|
const latestIndexAttempt = urlToLatestIndexAttempt.get(indexAttempt.url);
|
||||||
if (
|
if (
|
||||||
!latestIndexAttempt ||
|
!latestIndexAttempt ||
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
import { Header } from "@/components/Header";
|
import { Header } from "@/components/Header";
|
||||||
import { Sidebar } from "@/components/admin/connectors/Sidebar";
|
import { Sidebar } from "@/components/admin/connectors/Sidebar";
|
||||||
import { GlobeIcon, SlackIcon } from "@/components/icons/icons";
|
import { GlobeIcon, SlackIcon } from "@/components/icons/icons";
|
||||||
|
import { getCurrentUserSS } from "@/lib/userSS";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default function AdminLayout({
|
export default async function AdminLayout({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
|
const user = await getCurrentUserSS();
|
||||||
|
if (!user) {
|
||||||
|
return redirect("/auth/login");
|
||||||
|
}
|
||||||
|
if (user.role !== "admin") {
|
||||||
|
return redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header />
|
<Header user={user} />
|
||||||
<div className="bg-gray-900 pt-8 flex">
|
<div className="bg-gray-900 pt-8 flex">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
title="Connectors"
|
title="Connectors"
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import { Header } from "@/components/Header";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
|
||||||
import { Inter } from "next/font/google";
|
import { Inter } from "next/font/google";
|
||||||
|
import { getCurrentUserSS } from "@/lib/userSS";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
const inter = Inter({
|
const inter = Inter({
|
||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
@ -12,7 +15,7 @@ export const metadata = {
|
|||||||
description: "Question answering for your documents",
|
description: "Question answering for your documents",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default async function RootLayout({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
import { SearchSection } from "@/components/search/SearchSection";
|
import { SearchSection } from "@/components/search/SearchSection";
|
||||||
import { Header } from "@/components/Header";
|
import { Header } from "@/components/Header";
|
||||||
|
import { getCurrentUserSS } from "@/lib/userSS";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default function Home() {
|
export default async function Home() {
|
||||||
|
const user = await getCurrentUserSS();
|
||||||
|
if (!user) {
|
||||||
|
return redirect("/auth/login");
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header user={user} />
|
||||||
<div className="px-24 pt-10 flex flex-col items-center min-h-screen bg-gray-900 text-gray-100">
|
<div className="px-24 pt-10 flex flex-col items-center min-h-screen bg-gray-900 text-gray-100">
|
||||||
<div className="max-w-[800px] w-full">
|
<div className="max-w-[800px] w-full">
|
||||||
<SearchSection />
|
<SearchSection />
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { User } from "@/lib/types";
|
||||||
import { logout } from "@/lib/user";
|
import { logout } from "@/lib/user";
|
||||||
import { UserCircle } from "@phosphor-icons/react";
|
import { UserCircle } from "@phosphor-icons/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@ -7,7 +8,11 @@ import { useRouter } from "next/navigation";
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import "tailwindcss/tailwind.css";
|
import "tailwindcss/tailwind.css";
|
||||||
|
|
||||||
export const Header: React.FC = () => {
|
interface HeaderProps {
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||||
@ -64,11 +69,13 @@ export const Header: React.FC = () => {
|
|||||||
"w-36 overflow-hidden shadow-xl z-10 text-sm text-gray-300"
|
"w-36 overflow-hidden shadow-xl z-10 text-sm text-gray-300"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
{user.role === "admin" && (
|
||||||
<Link href="/admin/connectors/slack">
|
<Link href="/admin/connectors/slack">
|
||||||
<div className="flex py-2 px-3 cursor-pointer hover:bg-gray-500 border-b border-gray-500">
|
<div className="flex py-2 px-3 cursor-pointer hover:bg-gray-500 border-b border-gray-500">
|
||||||
Connectors
|
Connectors
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
className="flex py-2 px-3 cursor-pointer hover:bg-gray-500"
|
className="flex py-2 px-3 cursor-pointer hover:bg-gray-500"
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
|
@ -4,5 +4,5 @@ export interface User {
|
|||||||
is_active: string;
|
is_active: string;
|
||||||
is_superuser: string;
|
is_superuser: string;
|
||||||
is_verified: string;
|
is_verified: string;
|
||||||
role: string;
|
role: "basic" | "admin";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user