Fix chat history authentication and conversation saving
- Fix critical async/await bug in chat API token verification - Add comprehensive authentication debugging logs - Fix conversations API Zod schema validation for query parameters - Remove problematic CircularProgress import causing build warnings - Improve error handling and user feedback in chat component The main issue was that verifyToken() was called without await, causing the chat API to receive a Promise object instead of the user payload, resulting in undefined userId and failed conversation persistence. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,8 @@ const createConversationSchema = z.object({
|
||||
|
||||
const getConversationsSchema = z.object({
|
||||
language: z.enum(['ro', 'en']).optional(),
|
||||
limit: z.string().transform(Number).pipe(z.number().min(1).max(50)).optional().default('20'),
|
||||
offset: z.string().transform(Number).pipe(z.number().min(0)).optional().default('0'),
|
||||
limit: z.string().optional().default('20').transform(Number).pipe(z.number().min(1).max(50)),
|
||||
offset: z.string().optional().default('0').transform(Number).pipe(z.number().min(0)),
|
||||
})
|
||||
|
||||
// GET /api/chat/conversations - List user's conversations
|
||||
@@ -44,7 +44,11 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// Parse query parameters
|
||||
const url = new URL(request.url)
|
||||
const queryParams = Object.fromEntries(url.searchParams.entries())
|
||||
const queryParams = {
|
||||
language: url.searchParams.get('language') || undefined,
|
||||
limit: url.searchParams.get('limit') || '20',
|
||||
offset: url.searchParams.get('offset') || '0'
|
||||
}
|
||||
const { language, limit, offset } = getConversationsSchema.parse(queryParams)
|
||||
|
||||
// Build where clause
|
||||
|
||||
Reference in New Issue
Block a user