mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-07 19:38:19 +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 urlToLatestIndexSuccess = new Map<string, string>();
|
||||
data?.index_attempts.forEach((indexAttempt) => {
|
||||
data?.index_attempts?.forEach((indexAttempt) => {
|
||||
const latestIndexAttempt = urlToLatestIndexAttempt.get(indexAttempt.url);
|
||||
if (
|
||||
!latestIndexAttempt ||
|
||||
|
@ -1,15 +1,25 @@
|
||||
import { Header } from "@/components/Header";
|
||||
import { Sidebar } from "@/components/admin/connectors/Sidebar";
|
||||
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: React.ReactNode;
|
||||
}) {
|
||||
const user = await getCurrentUserSS();
|
||||
if (!user) {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
if (user.role !== "admin") {
|
||||
return redirect("/");
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header />
|
||||
<Header user={user} />
|
||||
<div className="bg-gray-900 pt-8 flex">
|
||||
<Sidebar
|
||||
title="Connectors"
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { Header } from "@/components/Header";
|
||||
import "./globals.css";
|
||||
|
||||
import { Inter } from "next/font/google";
|
||||
import { getCurrentUserSS } from "@/lib/userSS";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
@ -12,7 +15,7 @@ export const metadata = {
|
||||
description: "Question answering for your documents",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
|
@ -1,10 +1,16 @@
|
||||
import { SearchSection } from "@/components/search/SearchSection";
|
||||
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 (
|
||||
<>
|
||||
<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="max-w-[800px] w-full">
|
||||
<SearchSection />
|
||||
|
@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { User } from "@/lib/types";
|
||||
import { logout } from "@/lib/user";
|
||||
import { UserCircle } from "@phosphor-icons/react";
|
||||
import Link from "next/link";
|
||||
@ -7,7 +8,11 @@ import { useRouter } from "next/navigation";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import "tailwindcss/tailwind.css";
|
||||
|
||||
export const Header: React.FC = () => {
|
||||
interface HeaderProps {
|
||||
user: User;
|
||||
}
|
||||
|
||||
export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||
const router = useRouter();
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
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"
|
||||
}
|
||||
>
|
||||
<Link href="/admin/connectors/slack">
|
||||
<div className="flex py-2 px-3 cursor-pointer hover:bg-gray-500 border-b border-gray-500">
|
||||
Connectors
|
||||
</div>
|
||||
</Link>
|
||||
{user.role === "admin" && (
|
||||
<Link href="/admin/connectors/slack">
|
||||
<div className="flex py-2 px-3 cursor-pointer hover:bg-gray-500 border-b border-gray-500">
|
||||
Connectors
|
||||
</div>
|
||||
</Link>
|
||||
)}
|
||||
<div
|
||||
className="flex py-2 px-3 cursor-pointer hover:bg-gray-500"
|
||||
onClick={handleLogout}
|
||||
|
@ -4,5 +4,5 @@ export interface User {
|
||||
is_active: string;
|
||||
is_superuser: string;
|
||||
is_verified: string;
|
||||
role: string;
|
||||
role: "basic" | "admin";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user