Two top-level eager initializers were breaking pnpm build during Next.js
"collect page data" phase under SKIP_ENV_VALIDATION=1:
- src/lib/auth/index.ts created the better-auth singleton at module load,
triggering its "default secret" check against the unset BETTER_AUTH_SECRET.
- src/lib/minio/index.ts constructed `new Client({...})` at module load with
env.MINIO_ENDPOINT === undefined, throwing InvalidEndpointError.
Storage config now lives in system_settings (read at runtime by
getStorageBackend()), so the legacy @/lib/minio module's MinIO-client
exports were already unused — only buildStoragePath had real consumers.
Stripped the module to that single pure helper; deleted the dead
minioClient / ensureBucket / getPresignedUrl exports.
For better-auth, kept the existing call-site syntax (`auth.api.foo(...)`
and `typeof auth.$Infer.Session`) by wrapping the singleton in a Proxy
that lazy-instantiates on first property access. Build-time import never
touches env; first runtime request constructs as before.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
/**
|
|
* Storage path helper.
|
|
*
|
|
* Historically this module also exported a top-level `minioClient`,
|
|
* `ensureBucket()`, and `getPresignedUrl()` that read MINIO_* env vars
|
|
* eagerly at import-time. That broke the Next.js production build
|
|
* (the route-data collection phase imports route modules transitively,
|
|
* and modules touching `env.MINIO_*` blew up under SKIP_ENV_VALIDATION
|
|
* with `InvalidEndpointError: Invalid endPoint : undefined`).
|
|
*
|
|
* Storage config now lives in `system_settings` rows and is read at
|
|
* runtime by the pluggable backend in `@/lib/storage` (see
|
|
* `getStorageBackend()` and `presignDownloadUrl()`). Build-time env
|
|
* vars are no longer the source of truth.
|
|
*
|
|
* The only piece worth keeping in the legacy module path was this pure
|
|
* `buildStoragePath` helper, which doesn't touch env at all and is
|
|
* imported by several services. Everything else has been deleted.
|
|
*/
|
|
|
|
/**
|
|
* Constructs a storage path from typed components.
|
|
*
|
|
* Format: `{portSlug}/{entity}/{entityId}/{fileId}.{extension}`
|
|
*
|
|
* No user-supplied input should ever be used as path components — only
|
|
* UUIDs and controlled slugs (SECURITY-GUIDELINES.md §3.4, §7.1).
|
|
*/
|
|
export function buildStoragePath(
|
|
portSlug: string,
|
|
entity: string,
|
|
entityId: string,
|
|
fileId: string,
|
|
extension: string,
|
|
): string {
|
|
return `${portSlug}/${entity}/${entityId}/${fileId}.${extension}`;
|
|
}
|