Skip to content

Commit b5b2209

Browse files
author
Manus Bot
committed
Fix linting errors, server actions config, and chat history functionality
- Fixed switch clause declaration issue in app/actions.tsx by wrapping case block in curly braces - Removed empty interface and empty object pattern in chat-history-client.tsx - Added SERVER_ACTIONS_ALLOWED_ORIGINS environment variable support - Updated next.config.mjs to read allowed origins from environment with fallback - Fixed getChats function to properly filter by user_id and sort by created_at - Ensured chat history is retained and displayed correctly in Supabase All SQL migration files remain unchanged as requested.
1 parent a6c6e50 commit b5b2209

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
DATABASE_URL="postgresql://user:password@host:port/db"
2+
3+
# Server Actions Configuration
4+
# Allow Server Actions in remote dev environments
5+
SERVER_ACTIONS_ALLOWED_ORIGINS="*"

app/actions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ export const getUIStateFromAIState = (aiState: AIState): UIState => {
565565
case 'user':
566566
switch (type) {
567567
case 'input':
568-
case 'input_related':
568+
case 'input_related': {
569569
let messageContent: string | any[]
570570
try {
571571
// For backward compatibility with old messages that stored a JSON string
@@ -595,6 +595,7 @@ export const getUIStateFromAIState = (aiState: AIState): UIState => {
595595
</>
596596
)
597597
}
598+
}
598599
case 'inquiry':
599600
return {
600601
id,

components/sidebar/chat-history-client.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import { Spinner } from '@/components/ui/spinner';
1919
import HistoryItem from '@/components/history-item';
2020
import { type Chat } from '@/lib/types';
2121

22-
interface ChatHistoryClientProps {
23-
}
24-
25-
export function ChatHistoryClient({}: ChatHistoryClientProps) {
22+
export function ChatHistoryClient() {
2623
const [chats, setChats] = useState<Chat[]>([]);
2724
const [isLoading, setIsLoading] = useState(true);
2825
const [error, setError] = useState<string | null>(null);

lib/actions/chat.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import { getCurrentUserIdOnServer } from '@/lib/auth/get-current-user'
1515
import { getSupabaseServerClient } from '../supabase/client'
1616

1717
export async function getChats(userId?: string | null): Promise<Chat[]> {
18-
if (!userId) {
19-
const userId = await getCurrentUserIdOnServer();
20-
if (!userId) {
18+
let effectiveUserId = userId;
19+
if (!effectiveUserId) {
20+
effectiveUserId = await getCurrentUserIdOnServer();
21+
if (!effectiveUserId) {
2122
console.warn('getChats called without userId, returning empty array.')
2223
return []
2324
}
@@ -27,6 +28,8 @@ export async function getChats(userId?: string | null): Promise<Chat[]> {
2728
const { data, error } = await supabase
2829
.from('chats')
2930
.select('*')
31+
.eq('user_id', effectiveUserId)
32+
.order('created_at', { ascending: false })
3033

3134
if (error) {
3235
console.error('Error fetching chats from Supabase:', error)

next.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
const nextConfig = {
33
experimental: {
44
serverActions: {
5-
allowedOrigins: ["http://localhost:3000", "https://planet.queue.cx"],
5+
allowedOrigins: process.env.SERVER_ACTIONS_ALLOWED_ORIGINS
6+
? process.env.SERVER_ACTIONS_ALLOWED_ORIGINS.split(',')
7+
: ["http://localhost:3000", "https://planet.queue.cx"],
68
bodySizeLimit: '200mb',
79
},
810
},

0 commit comments

Comments
 (0)