upfynai-code 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,47 +100,23 @@ router.post('/login', (req, res, next) => {
100
100
  next();
101
101
  }, async (req, res) => {
102
102
  try {
103
- const { username, password, firstName, lastName, phone } = req.body;
103
+ const { username, password } = req.body;
104
104
 
105
105
  if (!username || !password) {
106
- return res.status(400).json({ error: 'Email and password are required' });
106
+ return res.status(400).json({ error: 'Identifier and password are required' });
107
107
  }
108
108
 
109
109
  const user = await userDb.getUserByUsername(username.trim());
110
110
  if (!user) {
111
- return res.status(401).json({ error: 'Invalid email or password' });
111
+ return res.status(401).json({ error: 'Invalid credentials' });
112
112
  }
113
113
 
114
114
  const isValidPassword = await bcrypt.compare(password, user.password_hash);
115
115
  if (!isValidPassword) {
116
- return res.status(401).json({ error: 'Invalid email or password' });
116
+ return res.status(401).json({ error: 'Invalid credentials' });
117
117
  }
118
118
 
119
- // Update name/phone if provided and different from stored values
120
- const fName = (firstName || '').trim().slice(0, 50);
121
- const lName = (lastName || '').trim().slice(0, 50);
122
- const ph = (phone || '').trim().slice(0, 20);
123
- const updates = [];
124
- const args = [];
125
- if (fName && fName !== user.first_name) { updates.push('first_name = ?'); args.push(fName); }
126
- if (lName && lName !== user.last_name) { updates.push('last_name = ?'); args.push(lName); }
127
- if (ph && ph !== user.phone) { updates.push('phone = ?'); args.push(ph); }
128
- if (fName && lName && `${fName} ${lName}` !== user.username) {
129
- updates.push('username = ?');
130
- args.push(`${fName} ${lName}`);
131
- } else if (fName && !lName && fName !== user.username && !user.last_name) {
132
- updates.push('username = ?');
133
- args.push(fName);
134
- }
135
- if (updates.length > 0) {
136
- try {
137
- args.push(user.id);
138
- await db.execute({ sql: `UPDATE users SET ${updates.join(', ')} WHERE id = ?`, args });
139
- } catch { /* non-critical profile update */ }
140
- }
141
-
142
- // Re-fetch user to get updated fields
143
- const updatedUser = updates.length > 0 ? (await userDb.getUserById(user.id)) || user : user;
119
+ const updatedUser = user;
144
120
 
145
121
  // Generate token + set cookie
146
122
  const token = generateToken(updatedUser);
@@ -254,6 +230,33 @@ router.get('/connect-token', authenticateToken, async (req, res) => {
254
230
  }
255
231
  });
256
232
 
233
+ // Update profile — phone only (email and other sensitive fields are read-only)
234
+ router.patch('/profile', authenticateToken, async (req, res) => {
235
+ try {
236
+ const userId = req.user.id;
237
+ const { phone } = req.body;
238
+
239
+ if (phone === undefined) {
240
+ return res.status(400).json({ error: 'No fields to update' });
241
+ }
242
+
243
+ const trimmed = (phone || '').trim().slice(0, 20);
244
+ if (trimmed && !/^[+]?[\d\s()-]{7,20}$/.test(trimmed)) {
245
+ return res.status(400).json({ error: 'Invalid phone format' });
246
+ }
247
+
248
+ await db.execute({ sql: 'UPDATE users SET phone = ? WHERE id = ?', args: [trimmed || null, userId] });
249
+
250
+ const updated = await userDb.getUserById(userId);
251
+ res.json({
252
+ success: true,
253
+ user: { phone: updated?.phone || null }
254
+ });
255
+ } catch (error) {
256
+ res.status(500).json({ error: 'Failed to update profile' });
257
+ }
258
+ });
259
+
257
260
  // Logout — clear the session cookie
258
261
  router.post('/logout', authenticateToken, (req, res) => {
259
262
  clearSessionCookie(res);