From ab330c64eeed9edfc2a6ef6a6f5cd38587ba0996 Mon Sep 17 00:00:00 2001
From: l3wdfut4pwr <l3wdfut4pwr@gmail.com>
Date: Mon, 27 Apr 2026 13:45:25 +0300
Subject: add username change and logout

---
 src/components/settings/changeusername.tsx | 41 ++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 src/components/settings/changeusername.tsx

(limited to 'src/components/settings/changeusername.tsx')

diff --git a/src/components/settings/changeusername.tsx b/src/components/settings/changeusername.tsx
new file mode 100644
index 0000000..c8527c4
--- /dev/null
+++ b/src/components/settings/changeusername.tsx
@@ -0,0 +1,41 @@
+const API_URL = process.env.NEXT_PUBLIC_API_URL;
+
+export const changeUsername = async (username: string) => {
+    try {
+        const res = await fetch(`${API_URL}/api/users/change-username`, {
+            method: 'PATCH',
+            headers: {
+                'Content-Type': 'application/json',
+            },
+            body: JSON.stringify({ username }),
+            credentials: 'include',
+        });
+
+        if (!res.ok) {
+            let errorData: any = null;
+
+            try {
+                errorData = await res.json();
+            } catch {}
+
+            return {
+                data: null,
+                error: {
+                    general: errorData?.detail || 'Ошибка изменения никнейма',
+                },
+            };
+        }
+
+        const data = await res.json();
+
+        return {
+            data,
+            error: null,
+        };
+    } catch (err: any) {
+        return {
+            data: null,
+            error: { general: err.message },
+        };
+    }
+};
-- 
cgit v1.3-3-g829e

