From e9eb2e9ab60133840328485b2b70b53488678a8f Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Thu, 21 Mar 2024 02:51:28 +0100 Subject: [PATCH] checks --- frontend/src/Components/ChangeUsername.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/Components/ChangeUsername.tsx b/frontend/src/Components/ChangeUsername.tsx index 247c2fb..e297a04 100644 --- a/frontend/src/Components/ChangeUsername.tsx +++ b/frontend/src/Components/ChangeUsername.tsx @@ -13,17 +13,23 @@ function ChangeUsername(): JSX.Element { const handleSubmit = async (): Promise => { try { // Call the API function to change the username - const token = localStorage.getItem("accessToken") ?? ""; + const token = localStorage.getItem("accessToken"); + if (!token) { + throw new Error("Access token not found"); + } + const response = await api.changeUserName( { prevName: "currentName", newName: newUsername }, token, ); + if (response.success) { // Optionally, add a success message or redirect the user console.log("Username changed successfully"); } else { // Handle the error message console.error("Failed to change username:", response.message); + setErrorMessage(response.message ?? "Failed to change username"); } } catch (error) { console.error("Error changing username:", error);