Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
trim at handler
Browse files Browse the repository at this point in the history
  • Loading branch information
KryptXBSA committed Oct 18, 2023
1 parent 2af33de commit e3aa070
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/handler/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"errors"
"net/http"
"strings"

"github.com/AlandSleman/StorageBox/auth"
"github.com/AlandSleman/StorageBox/prisma"
Expand All @@ -23,15 +24,16 @@ func Login(c *gin.Context) {
return
}

username := strings.ReplaceAll(body.Username, " ", "")
// Attempt to find the user by username
user, err := prisma.Client().User.FindFirst(
db.User.Username.Equals(body.Username),
db.User.Username.Equals(username),
).Exec(prisma.Context())

if err != nil {
if errors.Is(err, db.ErrNotFound) {
// User not found, create a new user
user, err = auth.CreateUserPassword(body.Username, body.Password)
user, err = auth.CreateUserPassword(username, body.Password)
if err != nil {
println(err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"message": "Server error"})
Expand Down

0 comments on commit e3aa070

Please sign in to comment.