package auth import ( "github.com/golang-jwt/jwt/v5" ) // LoginRequest represents the login request payload type LoginRequest struct { Username string `json:"username" binding:"required"` Password string `json:"password" binding:"required"` } // TokenResponse represents the token response type TokenResponse struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type"` // Biasanya "Bearer" ExpiresIn int64 `json:"expires_in"` // Durasi dalam detik } // JWTClaims represents the JWT claims type JWTClaims struct { UserID string `json:"sub"` // Gunakan "sub" (subject) sebagai standar untuk ID pengguna Username string `json:"username"` Email string `json:"email"` Role string `json:"role"` jwt.RegisteredClaims // Menanamkan klaim standar (exp, iat, iss, aud, dll.) } // RegisterRequest represents the register request payload type RegisterRequest struct { Username string `json:"username" binding:"required,min=3,max=50"` Email string `json:"email" binding:"required,email"` Password string `json:"password" binding:"required,min=6"` Role string `json:"role" binding:"required,oneof=admin user"` // Contoh validasi role } // RefreshTokenRequest represents the refresh token request payload type RefreshTokenRequest struct { RefreshToken string `json:"refresh_token" binding:"required"` } // User represents a user for authentication type User struct { ID string `json:"id"` Username string `json:"username"` Email string `json:"email"` Password string `json:"-"` // Tidak disertakan saat di-serialize ke JSON Role string `json:"role"` } // UserResponse represents user data that can be safely returned to the client type UserResponse struct { ID string `json:"id"` Username string `json:"username"` Email string `json:"email"` Role string `json:"role"` }