@@ -173,13 +173,24 @@ export async function HEAD(request, { params } = {}) {
173173 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } ) ;
174174 }
175175
176- const userId = user . id ;
177176 const { fileId } = await resolveRouteParams ( params ) ;
178177 const normalizedFileId = normalizeFileId ( fileId ) ;
179178 if ( ! normalizedFileId ) {
180179 return missingFileIdResponse ( ) ;
181180 }
182181
182+ const { data : internalUser , error : userError } = await supabase
183+ . from ( 'users' )
184+ . select ( 'id' )
185+ . eq ( 'auth_user_id' , user . id )
186+ . single ( ) ;
187+
188+ if ( userError || ! internalUser ) {
189+ return NextResponse . json ( { error : 'User profile not found' } , { status : 404 } ) ;
190+ }
191+
192+ const userId = internalUser . id ;
193+
183194 // Get file metadata from database
184195 const { data : fileData , error : fileError } = await supabase
185196 . from ( 'encrypted_files' )
@@ -189,13 +200,15 @@ export async function HEAD(request, { params } = {}) {
189200 created_at,
190201 messages!inner(
191202 conversation_id,
192- conversation_participants!inner(
193- user_id
203+ conversations!inner(
204+ conversation_participants!inner(
205+ user_id
206+ )
194207 )
195208 )
196209 ` )
197210 . eq ( 'id' , normalizedFileId )
198- . eq ( 'messages.conversation_participants.user_id' , userId )
211+ . eq ( 'messages.conversations. conversation_participants.user_id' , userId )
199212 . single ( ) ;
200213
201214 if ( fileError || ! fileData ) {
@@ -231,13 +244,25 @@ export async function POST(request, { params } = {}) {
231244 return NextResponse . json ( { error : 'Unauthorized' } , { status : 401 } ) ;
232245 }
233246
234- const userId = user . id ;
235247 const { fileId } = await resolveRouteParams ( params ) ;
236248 const normalizedFileId = normalizeFileId ( fileId ) ;
237249 if ( ! normalizedFileId ) {
238250 return missingFileIdResponse ( ) ;
239251 }
240252
253+ const authUserId = user . id ;
254+ const { data : internalUser , error : userError } = await supabase
255+ . from ( 'users' )
256+ . select ( 'id' )
257+ . eq ( 'auth_user_id' , authUserId )
258+ . single ( ) ;
259+
260+ if ( userError || ! internalUser ) {
261+ return NextResponse . json ( { error : 'User profile not found' } , { status : 404 } ) ;
262+ }
263+
264+ const userId = internalUser . id ;
265+
241266 console . log ( `📁 [FILE-INFO] Info request from user: ${ userId } for file: ${ fileId } ` ) ;
242267
243268 // Get file metadata from database
@@ -252,13 +277,15 @@ export async function POST(request, { params } = {}) {
252277 messages!inner(
253278 id,
254279 conversation_id,
255- conversation_participants!inner(
256- user_id
280+ conversations!inner(
281+ conversation_participants!inner(
282+ user_id
283+ )
257284 )
258285 )
259286 ` )
260287 . eq ( 'id' , normalizedFileId )
261- . eq ( 'messages.conversation_participants.user_id' , userId )
288+ . eq ( 'messages.conversations. conversation_participants.user_id' , userId )
262289 . single ( ) ;
263290
264291 if ( fileError || ! fileData ) {
@@ -274,7 +301,7 @@ export async function POST(request, { params } = {}) {
274301 encryptedMetadata : fileData . encrypted_metadata , // Client will decrypt
275302 createdAt : fileData . created_at ,
276303 createdBy : fileData . created_by ,
277- isOwner : fileData . created_by === userId
304+ isOwner : fileData . created_by === authUserId || fileData . created_by === userId
278305 } ) ;
279306
280307 } catch ( err ) {
0 commit comments