From aca65e070cdfb0cf685f45ec21e021e3bc8639e3 Mon Sep 17 00:00:00 2001 From: Supreme2580 Date: Thu, 5 Dec 2024 15:28:16 +0100 Subject: [PATCH] check world name --- backend/routes/worlds.go | 6 +++--- frontend/src/tabs/worlds/WorldsCreationPanel.js | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/backend/routes/worlds.go b/backend/routes/worlds.go index ec3fbfc7..02031625 100644 --- a/backend/routes/worlds.go +++ b/backend/routes/worlds.go @@ -713,14 +713,14 @@ func handleWorldRoute(w http.ResponseWriter, r *http.Request) { func checkWorldName(w http.ResponseWriter, r *http.Request) { routeutils.SetupAccessHeaders(w) - name := r.URL.Query().Get("name") + name := strings.TrimSpace(r.URL.Query().Get("name")) if name == "" { routeutils.WriteErrorJson(w, http.StatusBadRequest, "Missing name parameter") return } - // Check if name exists - exists, err := core.PostgresQueryOne[bool]("SELECT EXISTS(SELECT 1 FROM worlds WHERE name = $1)", name) + // Case-insensitive check if name exists + exists, err := core.PostgresQueryOne[bool]("SELECT EXISTS(SELECT 1 FROM worlds WHERE LOWER(name) = LOWER($1))", name) if err != nil { routeutils.WriteErrorJson(w, http.StatusInternalServerError, "Failed to check world name") return diff --git a/frontend/src/tabs/worlds/WorldsCreationPanel.js b/frontend/src/tabs/worlds/WorldsCreationPanel.js index 9347c3fd..e26b0814 100644 --- a/frontend/src/tabs/worlds/WorldsCreationPanel.js +++ b/frontend/src/tabs/worlds/WorldsCreationPanel.js @@ -163,10 +163,8 @@ const WorldsCreationPanel = (props) => { // Check if name exists const checkWorldNameExists = async (name) => { - const response = await fetchWrapper( - `check-world-name?name=${encodeURIComponent(name)}` - ); - if (response.data === 'true') { + const response = await fetchWrapper(`check-world-name?name=${name}`); + if (response.data === true) { setNameError('This world name already exists'); return true; } @@ -187,6 +185,7 @@ const WorldsCreationPanel = (props) => { // Check if name exists before submitting const nameExists = await checkWorldNameExists(worldName); + console.log('response: ', nameExists); if (nameExists) { return; }