mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-08 11:58:34 +02:00
Add support for DISABLE_AUTH on the FE
This commit is contained in:
parent
16ca6f760c
commit
d447b66039
@ -7,6 +7,7 @@ import {
|
||||
GoogleDriveIcon,
|
||||
SlackIcon,
|
||||
} from "@/components/icons/icons";
|
||||
import { DISABLE_AUTH } from "@/lib/constants";
|
||||
import { getCurrentUserSS } from "@/lib/userSS";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
@ -15,12 +16,15 @@ export default async function AdminLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const user = await getCurrentUserSS();
|
||||
if (!user) {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
if (user.role !== "admin") {
|
||||
return redirect("/");
|
||||
let user = null;
|
||||
if (!DISABLE_AUTH) {
|
||||
user = await getCurrentUserSS();
|
||||
if (!user) {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
if (user.role !== "admin") {
|
||||
return redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -1,7 +1,13 @@
|
||||
import { DISABLE_AUTH } from "@/lib/constants";
|
||||
import { getGoogleOAuthUrlSS, getCurrentUserSS } from "@/lib/userSS";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
const Page = async () => {
|
||||
// no need for any of the below if auth is disabled
|
||||
if (DISABLE_AUTH) {
|
||||
return redirect("/");
|
||||
}
|
||||
|
||||
const [currentUser, authorizationUrl] = await Promise.all([
|
||||
getCurrentUserSS(),
|
||||
getGoogleOAuthUrlSS(),
|
||||
|
@ -1,9 +1,6 @@
|
||||
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"],
|
||||
|
@ -2,11 +2,15 @@ import { SearchSection } from "@/components/search/SearchSection";
|
||||
import { Header } from "@/components/Header";
|
||||
import { getCurrentUserSS } from "@/lib/userSS";
|
||||
import { redirect } from "next/navigation";
|
||||
import { DISABLE_AUTH } from "@/lib/constants";
|
||||
|
||||
export default async function Home() {
|
||||
const user = await getCurrentUserSS();
|
||||
if (!user) {
|
||||
return redirect("/auth/login");
|
||||
let user = null;
|
||||
if (!DISABLE_AUTH) {
|
||||
user = await getCurrentUserSS();
|
||||
if (!user && !DISABLE_AUTH) {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
}
|
||||
return (
|
||||
<>
|
||||
|
@ -9,7 +9,7 @@ import { useRouter } from "next/navigation";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
interface HeaderProps {
|
||||
user: User;
|
||||
user: User | null;
|
||||
}
|
||||
|
||||
export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||
@ -74,19 +74,21 @@ export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||
"w-36 overflow-hidden shadow-xl z-10 text-sm text-gray-300"
|
||||
}
|
||||
>
|
||||
{user.role === "admin" && (
|
||||
{user?.role === "admin" && (
|
||||
<Link href="/admin/indexing/status">
|
||||
<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}
|
||||
>
|
||||
Logout
|
||||
</div>
|
||||
{user && (
|
||||
<div
|
||||
className="flex py-2 px-3 cursor-pointer hover:bg-gray-500"
|
||||
onClick={handleLogout}
|
||||
>
|
||||
Logout
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
1
web/src/lib/constants.ts
Normal file
1
web/src/lib/constants.ts
Normal file
@ -0,0 +1 @@
|
||||
export const DISABLE_AUTH = process.env.DISABLE_AUTH?.toLowerCase() === "true";
|
Loading…
x
Reference in New Issue
Block a user