Update besar

This commit is contained in:
meninjar
2025-10-31 02:30:27 +00:00
parent 07d264c57e
commit 0002cf26be
20 changed files with 4939 additions and 1938 deletions
+36 -9
View File
@@ -1,4 +1,8 @@
package models
package auth
import (
"github.com/golang-jwt/jwt/v5"
)
// LoginRequest represents the login request payload
type LoginRequest struct {
@@ -8,17 +12,32 @@ type LoginRequest struct {
// TokenResponse represents the token response
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
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:"user_id"`
Username string `json:"username"`
Email string `json:"email"`
Role string `json:"role"`
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
@@ -26,6 +45,14 @@ type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"-"`
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"`
}