Guard
Global auth hook for all S3 operations.
Runs on every request (upload, download, delete, multipart). Add guard to config (no enabled flag):
guard: async ({ request }) => {
// auth check
},Global guard
guard: async ({ request }) => {
const token = request.headers.get("authorization");
if (!token) throw Object.assign(new Error("Unauthorized"), { status: 401 });
},GuardContext
Prop
Type
import type { GuardContext } from "@dimah-s3/server";Throw to reject (403 by default). Attach { status: 401 } for other codes.
Example
import { dimahS3 } from "@dimah-s3/server";
import { s3Client, defaultBucket } from "@/lib/s3-client";
export const s3 = dimahS3({
s3: s3Client,
defaultBucket,
guard: async ({ request }) => {
const token = request.headers.get("authorization");
if (!token) throw Object.assign(new Error("Unauthorized"), { status: 401 });
},
upload: { enabled: true },
download: { enabled: true },
delete: { enabled: true },
});