Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/app/api/upload-auth/route.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { getUploadAuthParams } from "@imagekit/next/server"
import { auth } from "@/auth"

export async function GET() {
const session = await auth()
if (!session?.user) {
return Response.json({ error: "Unauthorized" }, { status: 401 })
}

try {
// Add authentication logic here if needed
// For example, check if user is logged in or has upload permissions

const { token, expire, signature } = getUploadAuthParams({
privateKey: process.env.IMAGEKIT_PRIVATE_KEY as string,
publicKey: process.env.NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY as string,
// expire: 30 * 60, // Optional: 30 minutes expiry, max 1 hour
});

return Response.json({
token,
expire,
signature,
publicKey: process.env.NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY
return Response.json({
token,
expire,
signature,
publicKey: process.env.NEXT_PUBLIC_IMAGEKIT_PUBLIC_KEY,
});
} catch (error) {
console.error('Upload auth error:', error);
Expand Down