From 30921b7513bbec087fc99081ae0537ec93bd277c Mon Sep 17 00:00:00 2001 From: Sakshi-Sharma08 Date: Sun, 24 May 2026 14:57:10 +0530 Subject: [PATCH 1/2] fix: persist users in SQLite database instead of in-memory store --- server.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index 47e1429..99b09dd 100644 --- a/server.js +++ b/server.js @@ -509,18 +509,20 @@ Text: "${text}" return res.json(tasks); }); // ================= AUTH ================= -const users = {}; // Simple in-memory user store - +// Users stored in SQLite database (persistent) app.post('/api/auth/signup', (req, res) => { const { email, password } = req.body; if (!email || !password) { return res.status(400).json({ error: 'Email and password required' }); } - if (users[email]) { - return res.status(400).json({ error: 'User already exists' }); - } - users[email] = { email, password }; - res.json({ success: true, message: 'Account created successfully' }); + db.get('SELECT * FROM users WHERE email = ?', [email], (err, row) => { + if (err) return res.status(500).json({ error: err.message }); + if (row) return res.status(400).json({ error: 'User already exists' }); + db.run('INSERT INTO users (email, password) VALUES (?, ?)', [email, password], function(err) { + if (err) return res.status(500).json({ error: err.message }); + res.json({ success: true, message: 'Account created successfully' }); + }); + }); }); app.post('/api/auth/login', (req, res) => { @@ -528,11 +530,11 @@ app.post('/api/auth/login', (req, res) => { if (!email || !password) { return res.status(400).json({ error: 'Email and password required' }); } - const user = users[email]; - if (!user || user.password !== password) { - return res.status(401).json({ error: 'Invalid email or password' }); - } - res.json({ success: true, email: user.email }); + db.get('SELECT * FROM users WHERE email = ? AND password = ?', [email, password], (err, row) => { + if (err) return res.status(500).json({ error: err.message }); + if (!row) return res.status(401).json({ error: 'Invalid email or password' }); + res.json({ success: true, email: row.email }); + }); }); // Intentional test route for verifying server error page behavior. @@ -572,4 +574,4 @@ app.use((err, req, res, next) => { const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log('Server running on port ' + PORT); -}); \ No newline at end of file +}); From c1e8e3d4e466bfef0bc77359b652b5f559652027 Mon Sep 17 00:00:00 2001 From: Sakshi-Sharma08 Date: Sun, 24 May 2026 15:04:31 +0530 Subject: [PATCH 2/2] fix: add users table to SQLite database for persistent authentication --- database.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/database.js b/database.js index 6fc7bec..49d9650 100644 --- a/database.js +++ b/database.js @@ -14,6 +14,13 @@ function initDb() { created_at DATETIME DEFAULT CURRENT_TIMESTAMP )`); + // Users Table + db.run(`CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + email TEXT UNIQUE NOT NULL, + password TEXT NOT NULL, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + )`); // Tasks Table db.run(`CREATE TABLE IF NOT EXISTS tasks ( id TEXT PRIMARY KEY,