This commit is contained in:
pavel Hamawand 2024-03-21 02:51:28 +01:00
parent baf11f19d6
commit e9eb2e9ab6

View file

@ -13,17 +13,23 @@ function ChangeUsername(): JSX.Element {
const handleSubmit = async (): Promise<void> => {
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);