Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .playwright-mcp/app-homepage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .playwright-mcp/chatbot-conversation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .playwright-mcp/successful-login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions CONSOLIDATION_PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# File Structure Consolidation Plan

## Current Issues
- Duplicate authentication logic across multiple files
- Scattered database operations
- Inconsistent file organization

## Recommended Structure

### 1. Authentication Consolidation
**Current:**
- `db/auth.ts` - Auth functions
- `lib/auth.ts` - getUser function
- `lib/auth/session.ts` - Session utilities
- `lib/auth/wallet.ts` - Wallet utilities

**Recommended:**
- `lib/auth/index.ts` - Main auth exports
- `lib/auth/client.ts` - Client-side auth functions
- `lib/auth/server.ts` - Server-side auth functions
- `lib/auth/session.ts` - Session management
- `lib/auth/wallet.ts` - Wallet integration

### 2. Database Operations Consolidation
**Current:**
- `db/queries.ts` - All queries
- `db/mutations.ts` - All mutations
- `db/cached-queries.ts` - Cached queries
- `db/storage.ts` - Storage operations

**Recommended:**
- `lib/database/index.ts` - Main database exports
- `lib/database/queries.ts` - All database queries
- `lib/database/mutations.ts` - All database mutations
- `lib/database/cache.ts` - Caching logic
- `lib/database/storage.ts` - Storage operations

### 3. Supabase Configuration (Keep As-Is)
**Current (CORRECT):**
- `supabase/` - Migrations and config
- `lib/supabase/` - Client configurations

## Migration Steps

1. **Create new structure:**
```bash
mkdir -p lib/database
mkdir -p lib/auth
```

2. **Move and consolidate files:**
- Move `db/*` to `lib/database/`
- Consolidate auth files into `lib/auth/`
- Update all imports

3. **Update imports across the codebase**

4. **Remove old `db/` folder**

## Benefits
- Clear separation of concerns
- Consistent file organization
- Easier maintenance
- Better TypeScript support
- Follows Next.js best practices
55 changes: 55 additions & 0 deletions VERCEL_ENV_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Vercel Environment Variables Setup

This document lists all the environment variables that need to be configured in Vercel for the application to work properly.

## Required Environment Variables

### Supabase Configuration
```
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
```

### OpenAI Configuration
```
OPENAI_API_KEY=your_openai_api_key
```

### Application Configuration
```
NEXT_PUBLIC_SITE_URL=https://your-domain.vercel.app
NEXT_PUBLIC_ENVIRONMENT=production
NODE_ENV=production
```

### Optional Features
```
NEXT_PUBLIC_FEATURE_ATTACHMENTS=true
NEXT_PUBLIC_FEATURE_WEB_SEARCH=true
```

### Optional Services
```
BING_API_KEY=your_bing_search_api_key
BLOB_READ_WRITE_TOKEN=your_vercel_blob_token
```

## How to Add Environment Variables in Vercel

1. Go to your Vercel dashboard
2. Select your project
3. Go to Settings β†’ Environment Variables
4. Add each variable with the appropriate value
5. Make sure to add them for all environments (Production, Preview, Development)

## Security Notes

- Never commit actual API keys to the repository
- Use Vercel's environment variables for all sensitive data
- The `SUPABASE_SERVICE_ROLE_KEY` should be kept secret
- The `OPENAI_API_KEY` should be kept secret

## Local Development

For local development, create a `.env.local` file with the same variables but use local Supabase URLs and keys.
8 changes: 4 additions & 4 deletions __tests__/chat-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ vi.mock("@/lib/supabase/server", () => ({
}),
}));

vi.mock("@/db/cached-queries", () => ({
vi.mock("@/lib/database/cached-queries", () => ({
getChatById: vi.fn(),
}));

vi.mock("@/db/mutations", () => ({
vi.mock("@/lib/database/mutations", () => ({
deleteChatById: vi.fn(),
}));

Expand All @@ -32,7 +32,7 @@ describe("Chat API Routes", () => {
it("should handle successful deletion", async () => {
const request = new Request("http://localhost:3000/api/chat?id=test-id");

const { getChatById } = await import("@/db/cached-queries");
const { getChatById } = await import("@/lib/database/cached-queries");
vi.mocked(getChatById).mockResolvedValueOnce({
user_id: "test-user-id",
});
Expand All @@ -44,7 +44,7 @@ describe("Chat API Routes", () => {
it("should handle unauthorized deletion", async () => {
const request = new Request("http://localhost:3000/api/chat?id=test-id");

const { getChatById } = await import("@/db/cached-queries");
const { getChatById } = await import("@/lib/database/cached-queries");
vi.mocked(getChatById).mockResolvedValueOnce({
user_id: "different-user-id",
});
Expand Down
13 changes: 6 additions & 7 deletions ai-bot-vercel.code-workspace
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
"folders": [
{
"path": "."
}
]
}
2 changes: 1 addition & 1 deletion app/(auth)/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { z } from "zod";

import { getUser } from "@/db/cached-queries";
import { getUser } from "@/lib/database/cached-queries";
import { createClient } from "@/lib/supabase/server";

const authFormSchema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { signIn, signInWithGitHub } from "@/db/auth";
import { signIn, signInWithGitHub } from "@/lib/auth/client";
import { errorHandler } from "@/lib/error-handling";

export default function LoginPage() {
Expand Down
2 changes: 1 addition & 1 deletion app/(auth)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { signUp, signInWithGitHub } from "@/db/auth";
import { signUp, signInWithGitHub } from "@/lib/auth/client";

export default function RegisterPage() {
const [isLoading, setIsLoading] = useState(false);
Expand Down
4 changes: 2 additions & 2 deletions app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { z } from "zod";
import { customModel } from "@/ai";
import { models } from "@/ai/models";
import { blocksPrompt, regularPrompt, systemPrompt } from "@/ai/prompts";
import { getChatById, getDocumentById, getSession } from "@/db/cached-queries";
import { getChatById, getDocumentById, getSession } from "@/lib/database/cached-queries";
import {
saveChat,
saveDocument,
saveMessages,
saveSuggestions,
deleteChatById,
} from "@/db/mutations";
} from "@/lib/database/mutations";
import { createClient } from "@/lib/supabase/server";
import { MessageRole } from "@/lib/supabase/types";
import {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/api/document/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";

import { saveDocument } from "@/db/mutations";
import { saveDocument } from "@/lib/database/mutations";
import { createClient } from "@/lib/supabase/server";

export async function GET(req: Request) {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/api/files/save/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";

import { saveDocument } from "@/db/mutations";
import { saveDocument } from "@/lib/database/mutations";
import { createClient } from "@/lib/supabase/server";

export async function POST(req: Request) {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/api/history/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSession } from "@/db/cached-queries";
import { getSession } from "@/lib/database/cached-queries";
import { createClient } from "@/lib/supabase/server";

export async function GET() {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/api/suggestions/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSession, getSuggestionsByDocumentId } from "@/db/cached-queries";
import { getSession, getSuggestionsByDocumentId } from "@/lib/database/cached-queries";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
Expand Down
4 changes: 2 additions & 2 deletions app/(chat)/api/vote/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getSession } from "@/db/cached-queries";
import { voteMessage } from "@/db/mutations";
import { getSession } from "@/lib/database/cached-queries";
import { voteMessage } from "@/lib/database/mutations";
import { createClient } from "@/lib/supabase/server";
export async function POST(request: Request) {
try {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/chat/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getChatById,
getMessagesByChatId,
getSession,
} from "@/db/cached-queries";
} from "@/lib/database/cached-queries";
import { convertToUIMessages } from "@/lib/utils";

export default async function Page(props: { params: Promise<any> }) {
Expand Down
2 changes: 1 addition & 1 deletion app/(chat)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cookies } from "next/headers";

import { AppSidebar } from "@/components/custom/app-sidebar";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import { getSession } from "@/db/cached-queries";
import { getSession } from "@/lib/database/cached-queries";

export default async function Layout({
children,
Expand Down
4 changes: 2 additions & 2 deletions app/(chat)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cookies } from "next/headers";

import { DEFAULT_MODEL_NAME, models } from "@/ai/models";
import { Chat } from "@/components/custom/chat";
import { ModernChat } from "@/components/custom/modern-chat";
import { generateUUID } from "@/lib/utils";

export default async function Page() {
Expand All @@ -15,7 +15,7 @@ export default async function Page() {
DEFAULT_MODEL_NAME;

return (
<Chat
<ModernChat
key={id}
id={id}
initialMessages={[]}
Expand Down
78 changes: 0 additions & 78 deletions app/auth/callback/page.tsx

This file was deleted.

21 changes: 21 additions & 0 deletions app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createClient } from "@/lib/supabase/server";
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");
const next = requestUrl.searchParams.get("next") ?? "/";

if (code) {
const supabase = await createClient();
const { error } = await supabase.auth.exchangeCodeForSession(code);

if (!error) {
// Session established successfully
return NextResponse.redirect(new URL(next, request.url));
}
}

// If there's an error or no code, redirect to auth error page
return NextResponse.redirect(new URL("/auth-error", request.url));
}
2 changes: 1 addition & 1 deletion components/custom/chat-history.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Suspense } from "react";

import { getChatsByUserId } from "@/db/cached-queries";
import { getChatsByUserId } from "@/lib/database/cached-queries";

import { ChatHistoryClient } from "./chat-history-client";
import { ChatHistorySkeleton } from "./chat-history-skeleton";
Expand Down
Loading
Loading