diff --git a/modules/auth/dto/refresh_token_dto.go b/modules/auth/dto/refresh_token_dto.go index 8b3f9cf..c8aa62a 100644 --- a/modules/auth/dto/refresh_token_dto.go +++ b/modules/auth/dto/refresh_token_dto.go @@ -10,7 +10,6 @@ const ( type TokenResponse struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` - Role string `json:"role"` } type RefreshTokenRequest struct { diff --git a/modules/auth/routes.go b/modules/auth/routes.go index 6f43ff6..84397b5 100644 --- a/modules/auth/routes.go +++ b/modules/auth/routes.go @@ -1,15 +1,21 @@ package auth import ( + "github.com/Caknoooo/go-gin-clean-starter/modules/user/controller" "github.com/gin-gonic/gin" "github.com/samber/do" ) func RegisterRoutes(server *gin.Engine, injector *do.Injector) { // Auth routes akan ditambahkan nanti ketika auth controller sudah dibuat + userController := do.MustInvoke[controller.UserController](injector) + authRoutes := server.Group("/api/v1/auth") { // authRoutes.POST("/refresh-token", authController.RefreshToken) - _ = authRoutes // untuk menghindari unused variable + authRoutes.POST("/register", userController.Register) + authRoutes.POST("/login", userController.Login) + authRoutes.POST("/verify-email", userController.VerifyEmail) + authRoutes.POST("/send-verification-email", userController.SendVerificationEmail) } } diff --git a/modules/auth/service/jwt_service.go b/modules/auth/service/jwt_service.go index 38fe3bf..b953bd0 100644 --- a/modules/auth/service/jwt_service.go +++ b/modules/auth/service/jwt_service.go @@ -12,21 +12,20 @@ import ( ) type UserTokenInfo struct { - TenantID string `json:"tenant_id"` + ClientID string `json:"client_id"` UserID string `json:"user_id"` } type JWTService interface { - GenerateAccessToken(tenantId string, userId string, role string) string + GenerateAccessToken(clientId string, userId string) string GenerateRefreshToken() (string, time.Time) ValidateToken(token string) (*jwt.Token, error) GetUserIDByToken(token string) (*UserTokenInfo, error) } type jwtCustomClaim struct { - TenantID string `json:"tenant_id"` + ClientID string `json:"client_id"` UserID string `json:"user_id"` - Role string `json:"role"` jwt.RegisteredClaims } @@ -55,11 +54,10 @@ func getSecretKey() string { return secretKey } -func (j *jwtService) GenerateAccessToken(tenantId string, userId string, role string) string { +func (j *jwtService) GenerateAccessToken(clientId string, userId string) string { claims := jwtCustomClaim{ - TenantID: tenantId, + ClientID: clientId, UserID: userId, - Role: role, RegisteredClaims: jwt.RegisteredClaims{ ExpiresAt: jwt.NewNumericDate(time.Now().Add(j.accessExpiry)), Issuer: j.issuer, @@ -108,9 +106,9 @@ func (j *jwtService) GetUserIDByToken(token string) (*UserTokenInfo, error) { claims := tToken.Claims.(jwt.MapClaims) userId := fmt.Sprintf("%v", claims["user_id"]) - tenantId := fmt.Sprintf("%v", claims["tenant_id"]) + clientId := fmt.Sprintf("%v", claims["client_id"]) return &UserTokenInfo{ UserID: userId, - TenantID: tenantId, + ClientID: clientId, }, nil }