Skip to content

Commit bcc7231

Browse files
committed
refactor: simplify registration settings check with environment fallback
1 parent 35a8534 commit bcc7231

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

backend/src/routes/auth.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,11 @@ const generateToken = (userId: string, username: string): string => {
4242
// POST /api/auth/register
4343
router.post('/register', authLimiter, async (req, res: Response, next: NextFunction) => {
4444
try {
45-
// 1. Check System Settings (DB)
45+
// 1. Check System Settings (DB) with fallback to Env
4646
const settings = await prisma.systemSettings.findFirst();
47-
let allowRegistration = true;
48-
49-
if (settings) {
50-
allowRegistration = settings.allowRegistration;
51-
} else {
52-
// 2. Fallback to Env if DB settings not exist
53-
allowRegistration = process.env.ALLOW_REGISTRATION !== 'false';
54-
}
47+
const allowRegistration = settings
48+
? settings.allowRegistration
49+
: process.env.ALLOW_REGISTRATION !== 'false';
5550

5651
if (!allowRegistration) {
5752
// 3. Exception: Allow registration if NO users exist (First Admin Setup)

0 commit comments

Comments
 (0)