fixed some imports need to reset db in docker

This commit is contained in:
Genuinely 2025-03-27 23:43:17 -07:00
parent c2306f9d20
commit 7f27c90b63
6 changed files with 51 additions and 23 deletions

View file

@ -2,4 +2,7 @@
* use `yard add` for new packages and the packages will be updated automatically
* auth-secret generate with `openssl rand -hex 32`
* need to no-cache if updating packages...don't need to remove `--frozen-lockfile` can be handled with `yarn`
* version 2 is using
* version 2 is using
### Adding userID to the schema
* complaining about userID column not existing find a way to reset the database within the docker container

View file

@ -6,7 +6,7 @@ general:
search:
autocomplete: 'google'
formats:
- html
# - html
- json
server:

View file

@ -21,7 +21,7 @@ import {
getCustomOpenaiModelName,
} from '@/lib/config';
import { searchHandlers } from '@/lib/search';
import { getSession } from '@auth0/nextjs-auth0';
import { auth0 } from '@/lib/auth0';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
@ -134,7 +134,7 @@ const handleHistorySave = async (
focusMode: string,
files: string[],
) => {
const session = await getSession();
const session = await auth0.getSession();
if (!session?.user) {
throw new Error('Unauthorized');
}

View file

@ -1,14 +1,14 @@
import db from '@/lib/db';
import { chats, messages } from '@/lib/db/schema';
import { eq, and } from 'drizzle-orm';
import { getSession } from '@auth0/nextjs-auth0';
import { auth0 } from '@/lib/auth0';
export const GET = async (
req: Request,
{ params }: { params: Promise<{ id: string }> },
) => {
try {
const session = await getSession();
const session = await auth0.getSession();
if (!session?.user) {
return Response.json({ message: 'Unauthorized' }, { status: 401 });
}
@ -51,7 +51,7 @@ export const DELETE = async (
{ params }: { params: Promise<{ id: string }> },
) => {
try {
const session = await getSession();
const session = await auth0.getSession();
if (!session?.user) {
return Response.json({ message: 'Unauthorized' }, { status: 401 });
}

View file

@ -1,26 +1,50 @@
import db from '@/lib/db';
import { getSession } from '@auth0/nextjs-auth0';
import { auth0 } from '@/lib/auth0';
import { chats } from '@/lib/db/schema'; // adjust this import to wherever your schema is defined
import { eq } from 'drizzle-orm';
export const GET = async (req: Request) => {
try {
const session = await getSession();
// Log that we're starting the request
console.log('Starting /api/chats GET request');
const session = await auth0.getSession();
console.log('Session status:', session ? 'exists' : 'null');
if (!session?.user) {
return Response.json({ message: 'Unauthorized' }, { status: 401 });
console.log('No session found, returning 401');
return Response.json(
{ message: 'Unauthorized - Please log in' },
{ status: 401 }
);
}
console.log('User ID:', session.user.sub);
// Log the database query attempt
console.log('Attempting database query');
let userChats = await db.query.chats.findMany({
where: eq(chats.userId, session.user.sub),
});
console.log('Query successful, found', userChats.length, 'chats');
userChats = userChats.reverse();
return Response.json({ chats: userChats }, { status: 200 });
} catch (err) {
console.error('Error in getting chats: ', err);
// Log the full error details
console.error('Detailed error in getting chats:', {
error: err,
message: err instanceof Error ? err.message : 'Unknown error',
stack: err instanceof Error ? err.stack : undefined
});
return Response.json(
{ message: 'An error has occurred.' },
{ status: 500 },
{
message: 'An error has occurred while fetching chats.',
details: err instanceof Error ? err.message : 'Unknown error'
},
{ status: 500 }
);
}
};

View file

@ -1,6 +1,17 @@
import { sql } from 'drizzle-orm';
import { text, integer, sqliteTable } from 'drizzle-orm/sqlite-core';
export const chats = sqliteTable('chats', {
id: text('id').primaryKey(),
userId: text('userId').notNull(), // user id from auth0
title: text('title').notNull(),
createdAt: text('createdAt').notNull(),
focusMode: text('focusMode').notNull(),
files: text('files', { mode: 'json' })
.$type<File[]>()
.default(sql`'[]'`),
});
export const messages = sqliteTable('messages', {
id: integer('id').primaryKey(),
content: text('content').notNull(),
@ -17,13 +28,3 @@ interface File {
fileId: string;
}
export const chats = sqliteTable('chats', {
id: text('id').primaryKey(),
userId: text('userId').notNull(), // user id from auth0
title: text('title').notNull(),
createdAt: text('createdAt').notNull(),
focusMode: text('focusMode').notNull(),
files: text('files', { mode: 'json' })
.$type<File[]>()
.default(sql`'[]'`),
});