allow to upload images

but also files, hmmmm
This commit is contained in:
2026-03-16 21:45:39 +03:00
parent 3a8bc6df2d
commit d8fc6e481f
18 changed files with 437 additions and 1 deletions

45
auth/cookies.go Normal file
View File

@@ -0,0 +1,45 @@
package auth
import (
"fmt"
"net/http"
"time"
)
func SetUserCookie(w http.ResponseWriter, token string, expiryTime time.Time) {
http.SetCookie(w, &http.Cookie{
Name: "token",
Value: token,
Secure: true,
HttpOnly: true,
Path: "/",
Expires: expiryTime,
SameSite: http.SameSiteStrictMode,
})
}
func RemoveUserCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: "token",
Value: "",
Secure: true,
HttpOnly: true,
Path: "/",
Expires: time.Now().Add(-time.Hour),
SameSite: http.SameSiteStrictMode,
})
}
func GetUserIdFromRequest(r *http.Request) (int64, error) {
c, err := r.Cookie("token")
if err != nil {
return -1, fmt.Errorf("no token cookie: %v", err)
}
userId, err := ValidateUserToken(c.Value)
if err != nil {
return -1, fmt.Errorf("invalid token: %v", err)
}
return userId, nil
}