Skip to content

Commit

Permalink
check world name
Browse files Browse the repository at this point in the history
  • Loading branch information
supreme2580 committed Dec 5, 2024
1 parent 166bb7a commit aca65e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions backend/routes/worlds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/tabs/worlds/WorldsCreationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit aca65e0

Please sign in to comment.