mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
Multiuser support (#60)
This commit is contained in:
31
lib/env.server.ts
Normal file
31
lib/env.server.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const zodEnv = z.object({
|
||||
AUTH_SECRET: z.string(),
|
||||
NEXT_PUBLIC_DEMO: z.string().optional(),
|
||||
})
|
||||
|
||||
declare global {
|
||||
interface ProcessEnv extends z.TypeOf<typeof zodEnv> {
|
||||
AUTH_SECRET: string;
|
||||
NEXT_PUBLIC_DEMO?: string;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
zodEnv.parse(process.env)
|
||||
} catch (err) {
|
||||
if (err instanceof z.ZodError) {
|
||||
const { fieldErrors } = err.flatten()
|
||||
const errorMessage = Object.entries(fieldErrors)
|
||||
.map(([field, errors]) =>
|
||||
errors ? `${field}: ${errors.join(", ")}` : field,
|
||||
)
|
||||
.join("\n ")
|
||||
|
||||
console.error(
|
||||
`Missing environment variables:\n ${errorMessage}`,
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user