fix: update searchParams type to Promise and resolve before accessing id
This commit is contained in:
		
							parent
							
								
									24d90a9412
								
							
						
					
					
						commit
						d4661dc8e3
					
				| @ -24,9 +24,10 @@ interface FileDetails { | |||||||
| export async function generateMetadata({ | export async function generateMetadata({ | ||||||
|   searchParams, |   searchParams, | ||||||
| }: { | }: { | ||||||
|   searchParams: { id?: string }; |   searchParams: Promise<{ id?: string }>; | ||||||
| }): Promise<Metadata> { | }): Promise<Metadata> { | ||||||
|   const fileId = searchParams.id; |   const resolvedSearchParams = await searchParams; // Resolve the promise
 | ||||||
|  |   const fileId = resolvedSearchParams.id; | ||||||
| 
 | 
 | ||||||
|   if (!fileId) { |   if (!fileId) { | ||||||
|     return { |     return { | ||||||
| @ -84,9 +85,10 @@ async function fetchFileDetails(fileId: string): Promise<FileDetails | null> { | |||||||
| export default async function FilePreviewContainer({ | export default async function FilePreviewContainer({ | ||||||
|   searchParams, |   searchParams, | ||||||
| }: { | }: { | ||||||
|   searchParams: { id?: string }; |   searchParams: Promise<{ id?: string }>; | ||||||
| }) { | }) { | ||||||
|   const fileId = searchParams.id; |   const resolvedSearchParams = await searchParams; // Resolve the promise
 | ||||||
|  |   const fileId = resolvedSearchParams.id; | ||||||
| 
 | 
 | ||||||
|   if (!fileId) { |   if (!fileId) { | ||||||
|     notFound(); |     notFound(); | ||||||
|  | |||||||
| @ -18,18 +18,20 @@ export const postRouter = createTRPCRouter({ | |||||||
|   create: protectedProcedure |   create: protectedProcedure | ||||||
|     .input(z.object({ name: z.string().min(1) })) |     .input(z.object({ name: z.string().min(1) })) | ||||||
|     .mutation(async ({ ctx, input }) => { |     .mutation(async ({ ctx, input }) => { | ||||||
|       return ctx.db.post.create({ |       return ctx.db.file.create({ | ||||||
|         data: { |         data: { | ||||||
|           name: input.name, |           name: input.name, | ||||||
|           createdBy: { connect: { id: ctx.session.user.id } }, |           url: "default-url", // Replace with actual URL logic
 | ||||||
|  |           size: 0, // Replace with actual size logic
 | ||||||
|  |           extension: "txt", // Replace with actual extension logic
 | ||||||
|         }, |         }, | ||||||
|       }); |       }); | ||||||
|     }), |     }), | ||||||
| 
 | 
 | ||||||
|   getLatest: protectedProcedure.query(async ({ ctx }) => { |   getLatest: protectedProcedure.query(async ({ ctx }) => { | ||||||
|     const post = await ctx.db.post.findFirst({ |     const post = await ctx.db.file.findFirst({ | ||||||
|       orderBy: { createdAt: "desc" }, |       orderBy: { uploadDate: "desc" }, // Replace 'createdAt' with the correct field name from your schema
 | ||||||
|       where: { createdBy: { id: ctx.session.user.id } }, |       where: { uploadedById: ctx.session.user.id }, | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return post ?? null; |     return post ?? null; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user