From cfb28b709fea1f7a0430f42050b6dcaa2676fe28 Mon Sep 17 00:00:00 2001 From: Arkaprabha Chakraborty Date: Fri, 13 Feb 2026 01:09:23 +0530 Subject: [PATCH] fix: remove an unused feat --- backend/auth.go | 37 ------------------------ backend/main.go | 1 - frontend/src/pages/User.tsx | 57 ++----------------------------------- 3 files changed, 2 insertions(+), 93 deletions(-) diff --git a/backend/auth.go b/backend/auth.go index 23e3e77..0f42bd0 100644 --- a/backend/auth.go +++ b/backend/auth.go @@ -232,43 +232,6 @@ func getMe(c echo.Context) error { }) } -func updateUsername(c echo.Context) error { - uid := c.Get("user_id").(uint) - type Req struct { - Username string `json:"username"` - } - r := new(Req) - if err := c.Bind(r); err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Invalid request") - } - - r.Username = strings.TrimSpace(r.Username) - if len(r.Username) < 3 || len(r.Username) > 32 { - return echo.NewHTTPError(http.StatusBadRequest, "Username must be 3–32 characters") - } - - // Check if username is already taken by another user - var existing User - if db.Where("username = ? AND id != ?", r.Username, uid).First(&existing).Error == nil { - return echo.NewHTTPError(http.StatusConflict, "Username already taken") - } - - var user User - if err := db.First(&user, uid).Error; err != nil { - return echo.NewHTTPError(http.StatusNotFound, "User not found") - } - - user.Username = r.Username - if err := db.Save(&user).Error; err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update username") - } - - return c.JSON(http.StatusOK, map[string]interface{}{ - "id": user.ID, - "username": user.Username, - }) -} - func updatePassword(c echo.Context) error { uid := c.Get("user_id").(uint) type Req struct { diff --git a/backend/main.go b/backend/main.go index a852b7c..a357049 100644 --- a/backend/main.go +++ b/backend/main.go @@ -45,7 +45,6 @@ func main() { // User account management user := e.Group("/user", JWTMiddleware) user.GET("/stats", getUserStats) - user.PUT("/username", updateUsername) user.PUT("/password", updatePassword) user.DELETE("/account", deleteAccount) diff --git a/frontend/src/pages/User.tsx b/frontend/src/pages/User.tsx index 840e6d6..83fddee 100644 --- a/frontend/src/pages/User.tsx +++ b/frontend/src/pages/User.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import api from '../lib/api'; -import { MdPerson, MdLock, MdDelete, MdSave, MdBarChart } from 'react-icons/md'; +import { MdLock, MdDelete, MdSave, MdBarChart } from 'react-icons/md'; interface UserStats { link_count: number; @@ -18,10 +18,6 @@ export default function User() { const [error, setError] = useState(''); const [success, setSuccess] = useState(''); - // Username update - const [newUsername, setNewUsername] = useState(''); - const [updatingUsername, setUpdatingUsername] = useState(false); - // Password update const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); @@ -39,7 +35,6 @@ export default function User() { useEffect(() => { if (user) { - setNewUsername(user.username); fetchStats(); } }, [user]); @@ -55,23 +50,6 @@ export default function User() { } }; - const handleUpdateUsername = async (e: React.FormEvent) => { - e.preventDefault(); - setError(''); - setSuccess(''); - setUpdatingUsername(true); - - try { - setSuccess('Username updated successfully'); - // Update the user in context would require refetching /auth/me - window.location.reload(); // Simple way to update context - } catch (err: any) { - setError(err.response?.data?.message || 'Failed to update username'); - } finally { - setUpdatingUsername(false); - } - }; - const handleUpdatePassword = async (e: React.FormEvent) => { e.preventDefault(); setError(''); @@ -121,7 +99,7 @@ export default function User() { return (
-
+
{/* Header */}

Account Settings @@ -157,37 +135,6 @@ export default function User() {

- {/* Update Username */} -
-
- -

Username

-
-
-
- - setNewUsername(e.target.value)} - className="w-full bg-zinc-950 border border-zinc-800 px-4 py-2 text-zinc-100 text-sm focus:outline-none focus:border-zinc-600" - required - minLength={3} - maxLength={32} - /> -
- -
-
- {/* Update Password */}