Add logout function and ADMIN_PASSWORD environment validation
This commit is contained in:
10
lib/auth.ts
10
lib/auth.ts
@@ -22,6 +22,16 @@ export async function requireAdminAuth(request: NextRequest): Promise<NextRespon
|
||||
*/
|
||||
export async function verifyAdminPassword(password: string): Promise<boolean> {
|
||||
const bcrypt = await import('bcryptjs');
|
||||
|
||||
// Validate that ADMIN_PASSWORD is set (security best practice)
|
||||
if (!process.env.ADMIN_PASSWORD) {
|
||||
console.error('SECURITY WARNING: ADMIN_PASSWORD environment variable is not set!');
|
||||
// Fallback to default hash only in development
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
throw new Error('ADMIN_PASSWORD environment variable is required in production');
|
||||
}
|
||||
}
|
||||
|
||||
const adminPasswordHash = process.env.ADMIN_PASSWORD || '$2b$10$SHOt9G1qUNIvHoWre7499.eEtp5PtOII0daOQGNV.dhDEuPmOUdsq';
|
||||
return bcrypt.compare(password, adminPasswordHash);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user