use login context with newmessage

This commit is contained in:
2025-04-07 22:18:54 -04:00
parent 32bfd109b9
commit 14c78536de
3 changed files with 14 additions and 7 deletions

View File

@@ -115,11 +115,14 @@ func NewMessage(w http.ResponseWriter, r *http.Request) {
return
}
userID := r.FormValue("user_id")
if userID == "" {
http.Error(w, "Invalid user ID", http.StatusBadRequest)
return
}
// userID := r.FormValue("user_id")
//if userID == "" {
// http.Error(w, "Invalid user ID", http.StatusBadRequest)
// return
//}
var user = r.Context().Value(userKey{}).(*User)
body := r.FormValue("body")
if body == "" {
@@ -129,7 +132,7 @@ func NewMessage(w http.ResponseWriter, r *http.Request) {
msg := Message{
ID: newMessageID(),
UserID: userID,
UserID: user.ID,
Body: body,
Timestamp: time.Now(),
Edited: time.Time{},