feat(ui): Add tenant info
This commit is contained in:
@@ -16,17 +16,20 @@ import (
|
||||
// Provides functionality for user registration, login, logout, and token management
|
||||
// through the REST API endpoints
|
||||
type AuthHandler struct {
|
||||
userService interfaces.UserService
|
||||
userService interfaces.UserService
|
||||
tenantService interfaces.TenantService
|
||||
}
|
||||
|
||||
// NewAuthHandler creates a new auth handler instance with the provided service
|
||||
// NewAuthHandler creates a new auth handler instance with the provided services
|
||||
// Parameters:
|
||||
// - userService: An implementation of the UserService interface for business logic
|
||||
// - tenantService: An implementation of the TenantService interface for tenant management
|
||||
//
|
||||
// Returns a pointer to the newly created AuthHandler
|
||||
func NewAuthHandler(userService interfaces.UserService) *AuthHandler {
|
||||
func NewAuthHandler(userService interfaces.UserService, tenantService interfaces.TenantService) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
userService: userService,
|
||||
userService: userService,
|
||||
tenantService: tenantService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +217,7 @@ func (h *AuthHandler) RefreshToken(c *gin.Context) {
|
||||
func (h *AuthHandler) GetCurrentUser(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
|
||||
logger.Info(ctx, "Get current user info")
|
||||
logger.Debugf(ctx, "Get current user info")
|
||||
|
||||
// Get current user from service (which extracts from context)
|
||||
user, err := h.userService.GetCurrentUser(ctx)
|
||||
@@ -225,10 +228,25 @@ func (h *AuthHandler) GetCurrentUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Retrieved current user info: %s", user.Email)
|
||||
// Get tenant information
|
||||
var tenant *types.Tenant
|
||||
if user.TenantID > 0 {
|
||||
tenant, err = h.tenantService.GetTenantByID(ctx, user.TenantID)
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "Failed to get tenant info for user %s, tenant ID %d: %v", user.Email, user.TenantID, err)
|
||||
// Don't fail the request if tenant info is not available
|
||||
} else {
|
||||
logger.Debugf(ctx, "Retrieved tenant info for user %s: %s", user.Email, tenant.Name)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debugf(ctx, "Retrieved current user info: %s", user.Email)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"user": user.ToUserInfo(),
|
||||
"data": gin.H{
|
||||
"user": user.ToUserInfo(),
|
||||
"tenant": tenant,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user