Conversation
Co-authored-by: Jean <jean@analoginterface.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
apps/web/src/app/api/upload/route.ts
Outdated
| // Configure the upload router with S3 | ||
| // The aws() client automatically reads from environment variables: | ||
| // - AWS_ACCESS_KEY_ID | ||
| // - AWS_SECRET_ACCESS_KEY | ||
| // - AWS_REGION |
There was a problem hiding this comment.
remove all the comments, except for: // 100MB in bytes
apps/web/src/app/api/upload/route.ts
Outdated
| export async function POST(request: Request) { | ||
| // Get the session from better-auth | ||
| const headersList = await headers(); | ||
| const session = await auth.api.getSession({ | ||
| headers: headersList, | ||
| }); | ||
|
|
||
| // Check if user is authenticated | ||
| if (!session?.user) { | ||
| return new Response( | ||
| JSON.stringify({ | ||
| error: "Unauthorized", | ||
| message: "You must be logged in to upload files", | ||
| }), | ||
| { | ||
| status: 401, | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| // User is authenticated, proceed with upload | ||
| return uploadPOST(request); | ||
| } |
There was a problem hiding this comment.
instead use:
import { RejectUpload, route, type Router } from '@better-upload/server';
import { aws } from '@better-upload/server/clients';
const auth = (req: Request) => ({ id: 'fake-user-id' });
const router: Router = {
client: aws(),
bucketName: 'my-bucket',
routes: {
images: route({
fileTypes: ['image/*'],
multipleFiles: true,
maxFiles: 4,
onBeforeUpload: async ({ req, files, clientMetadata }) => {
const user = await auth(req);
if (!user) {
throw new RejectUpload('Not logged in!');
}
},
}),
},
};
package.json
Outdated
| ], | ||
| "dependencies": { | ||
| "@better-upload/client": "^3.0.2", | ||
| "@better-upload/server": "^3.0.2" | ||
| } |
There was a problem hiding this comment.
are you fucking retarded, install it in apps/web
|
@tembo fix it based on the review and run format |
Done! I've addressed all the feedback:
|
Description
Implements server-side file upload to AWS S3 using
better-uploadwithbetter-authintegration. Supports up to 10 files, 100MB each, any content type.Screenshots / Recordings
Type of Change
Related Areas
Testing
Checklist
Notes
Added
/api/uploadroute, configuredbetter-uploadfor S3, and enforced authentication. Updated.env.exampleandenv/server.tsfor AWS S3 credentials. Addedbetter-uploaddependencies.By submitting, I confirm I understand and stand behind this code. If AI was used, I’ve reviewed and verified everything myself.
Summary by cubic
Adds an authenticated server-side S3 upload endpoint at /api/upload using better-upload. Supports up to 10 files (100MB each) with any content type.
New Features
Migration
Written for commit f1fbee7. Summary will update automatically on new commits.