fix: support virtual-hosted S3 URLs for avatar storage (#330)
Avatar images failed to load with 403 on Tigris and newer AWS S3 buckets because getAvatarUrl only constructed path-style URLs. Modern S3-compatible providers require virtual-hosted URLs (bucket.domain/key). Add NEXT_PUBLIC_STORAGE_DOMAIN env var to signal URL style: - If set: virtual-hosted URL (Tigris, AWS S3) - If not set: path-style URL (MinIO, LocalStack) - backward compatible Add vitest and tests for getAvatarUrl behavior. Co-authored-by: Sachin Divekar <sachin.divekar@remiges.tech>
This commit is contained in:
@@ -52,5 +52,13 @@ export const getAvatarUrl = (imageOrKey: string | null) => {
|
||||
return imageOrKey;
|
||||
}
|
||||
|
||||
return `${env("NEXT_PUBLIC_STORAGE_URL")}/${env("NEXT_PUBLIC_AVATAR_BUCKET_NAME")}/${imageOrKey}`;
|
||||
const bucket = env("NEXT_PUBLIC_AVATAR_BUCKET_NAME");
|
||||
const storageDomain = env("NEXT_PUBLIC_STORAGE_DOMAIN");
|
||||
|
||||
if (storageDomain) {
|
||||
return `https://${bucket}.${storageDomain}/${imageOrKey}`;
|
||||
}
|
||||
|
||||
const storageUrl = env("NEXT_PUBLIC_STORAGE_URL");
|
||||
return `${storageUrl}/${bucket}/${imageOrKey}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user