make auth optional

This commit is contained in:
Ramnique Singh 2025-03-27 07:58:15 +05:30
parent 4b3395ea3a
commit 861bae11a6
9 changed files with 73 additions and 27 deletions

View file

@ -11,10 +11,18 @@ import { getAgenticApiResponse, getAgenticResponseStreamId } from "../lib/utils"
import { check_query_limit } from "../lib/rate_limiting";
import { QueryLimitError } from "../lib/client_utils";
import { projectAuthCheck } from "./project_actions";
import { USE_AUTH } from "../lib/feature_flags";
const crawler = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY || '' });
export async function authCheck(): Promise<Claims> {
if (!USE_AUTH) {
return {
email: 'guestuser@rowboatlabs.com',
email_verified: true,
sub: 'guest_user',
};
}
const { user } = await getSession() || {};
if (!user) {
throw new Error('User not authenticated');

View file

@ -10,8 +10,12 @@ import { authCheck } from "./actions";
import { WithStringId } from "../lib/types/types";
import { ApiKey } from "../lib/types/project_types";
import { Project } from "../lib/types/project_types";
import { USE_AUTH } from "../lib/feature_flags";
export async function projectAuthCheck(projectId: string) {
if (!USE_AUTH) {
return;
}
const user = await authCheck();
const membership = await projectMembersCollection.findOne({
projectId,

View file

@ -1,4 +1,5 @@
export const USE_RAG = process.env.USE_RAG === 'true';
export const USE_RAG_UPLOADS = process.env.USE_RAG_UPLOADS === 'true';
export const USE_RAG_SCRAPING = process.env.USE_RAG_SCRAPING === 'true';
export const USE_CHAT_WIDGET = process.env.USE_CHAT_WIDGET === 'true';
export const USE_CHAT_WIDGET = process.env.USE_CHAT_WIDGET === 'true';
export const USE_AUTH = process.env.USE_AUTH === 'true';

View file

@ -1,5 +1,12 @@
import { App } from "./app";
import { redirect } from "next/navigation";
import { USE_AUTH } from "./lib/feature_flags";
export const dynamic = 'force-dynamic';
export default function Home() {
if (!USE_AUTH) {
redirect("/projects");
}
return <App />
}

View file

@ -4,6 +4,9 @@ import Image from "next/image";
import Link from "next/link";
import { UserButton } from "../lib/components/user_button";
import { ThemeToggle } from "../lib/components/theme-toggle";
import { USE_AUTH } from "../lib/feature_flags";
export const dynamic = 'force-dynamic';
export default function Layout({
children,
@ -30,7 +33,7 @@ export default function Layout({
</div>
<div className="flex items-center gap-2">
<ThemeToggle />
<UserButton />
{USE_AUTH && <UserButton />}
</div>
</header>
<main className="grow overflow-auto">

View file

@ -34,6 +34,10 @@ export async function middleware(request: NextRequest, event: NextFetchEvent) {
}
if (request.nextUrl.pathname.startsWith('/projects')) {
// Skip auth check if USE_AUTH is not enabled
if (process.env.USE_AUTH !== 'true') {
return NextResponse.next();
}
return auth0MiddlewareHandler(request, event);
}