feat: add authorization
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
export interface Environment {
|
||||
DATABASE_URL: string;
|
||||
FRONTEND_ORIGIN: string;
|
||||
JWT_SECRET: string;
|
||||
PORT: number;
|
||||
}
|
||||
|
||||
@@ -8,6 +9,7 @@ export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
const databaseUrl = config['DATABASE_URL'];
|
||||
const frontendOrigin = config['FRONTEND_ORIGIN'];
|
||||
const port = config['PORT'] ?? 3000;
|
||||
const jwtSecret = config['JWT_SECRET'];
|
||||
|
||||
if (typeof databaseUrl !== 'string' || !databaseUrl.startsWith('file:')) {
|
||||
throw new Error('DATABASE_URL must be a SQLite file URL');
|
||||
@@ -38,9 +40,14 @@ export function validateEnv(config: Record<string, unknown>): Environment {
|
||||
throw new Error('PORT must be a valid port number');
|
||||
}
|
||||
|
||||
if (typeof jwtSecret !== 'string' || jwtSecret.length < 32) {
|
||||
throw new Error('JWT_SECRET must be at least 32 characters long');
|
||||
}
|
||||
|
||||
return {
|
||||
DATABASE_URL: databaseUrl,
|
||||
FRONTEND_ORIGIN: parsedOrigin.origin,
|
||||
JWT_SECRET: jwtSecret,
|
||||
PORT: parsedPort,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user