add web ui and user route

This commit is contained in:
2026-02-15 19:29:09 +03:00
parent 8d9b5c32c6
commit 7ced62517a
24 changed files with 3025 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package auth
import (
"fmt"
"os"
"time"
@@ -28,3 +29,20 @@ func GenerateUserToken(userId int64, expiryTime time.Time) (string, error) {
return token.SignedString([]byte(secretKey))
}
func ValidateUserToken(token string) (int64, error) {
claims := &UserClaims{}
parsed, err := jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {
return []byte(secretKey), nil
})
if err != nil {
return -1, fmt.Errorf("failed to parse token: %v", err)
}
if !parsed.Valid {
return -1, fmt.Errorf("invalid token")
}
return claims.UserID, nil
}