diff --git a/packages/auth/auth.go b/packages/auth/auth.go index 06a6cb0..200fcb3 100644 --- a/packages/auth/auth.go +++ b/packages/auth/auth.go @@ -163,7 +163,7 @@ func refresh(w http.ResponseWriter, r *http.Request) { _, claims, _ := jwtauth.FromContext(r.Context()) w.WriteHeader(http.StatusOK) expirationTime := time.Now().Add(5 * time.Hour) - newClaims := &Claims{ + newClaims := &Claims{ Username: claims["username"].(string), StandardClaims: jwt.StandardClaims{ ExpiresAt: expirationTime.Unix(), diff --git a/packages/users/users.go b/packages/users/users.go index fe2d45e..bc53a0a 100644 --- a/packages/users/users.go +++ b/packages/users/users.go @@ -2,6 +2,7 @@ package users import ( "database/sql" + "encoding/json" "fmt" "github.com/go-chi/chi" "github.com/go-chi/jwtauth" @@ -15,10 +16,10 @@ var ( ) type User struct { - Username string `json:"username"` - Email string `json:"email"` - Country string `json:"country"` - Bio string `json:"bio"` + Username string `json:"username",db:"username"` + Email string `json:"email",db:"email"` + Country string `json:"country",db:"country"` + Bio string `json:"bio",db:"bio"` } func Init() { @@ -64,6 +65,22 @@ func updateUser(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusUnauthorized) return } + user := &User{} + err := json.NewDecoder(r.Body).Decode(user) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + user.Username = username + updateProfileStatement := ` + UPDATE user_profiles + SET username = $1, + email = $2, + country = $3, + bio = $4 + WHERE username = $5` + _, err = DB.Exec(updateProfileStatement, user.Username, user.Email, user.Country, user.Bio, username) + fmt.Println(err) return }