fix: properly handle repository errors and remove unused hash field

- fix: wrap errors from sessionRepo.Delete, credentialRepo operations
  with internal error context in Logout, ListPasskeys, and RevokePasskey
- fix: remove Hash field from fileInfoResponse DTO (unused)
This commit is contained in:
2026-07-05 23:57:19 +08:00
parent 63ede5c237
commit 3ad61244dc
2 changed files with 13 additions and 5 deletions
-2
View File
@@ -61,7 +61,6 @@ type fileInfoResponse struct {
Size int64 `json:"size"` Size int64 `json:"size"`
MimeType string `json:"mime_type"` MimeType string `json:"mime_type"`
IsDir bool `json:"is_dir"` IsDir bool `json:"is_dir"`
Hash string `json:"hash,omitempty"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
} }
@@ -343,7 +342,6 @@ func toFileInfoResponse(info *service.FileInfo) fileInfoResponse {
Size: info.Size, Size: info.Size,
MimeType: info.MimeType, MimeType: info.MimeType,
IsDir: info.IsDir, IsDir: info.IsDir,
Hash: info.Hash,
CreatedAt: info.CreatedAt, CreatedAt: info.CreatedAt,
UpdatedAt: info.UpdatedAt, UpdatedAt: info.UpdatedAt,
} }
+13 -3
View File
@@ -162,7 +162,10 @@ func (s *AuthService) Logout(ctx context.Context, refreshTokenStr string) error
return model.NewInternalError("find session", err) return model.NewInternalError("find session", err)
} }
return s.sessionRepo.Delete(ctx, session.ID) if err := s.sessionRepo.Delete(ctx, session.ID); err != nil {
return model.NewInternalError("delete session", err)
}
return nil
} }
// CreatePasskey creates a new app passkey for the authenticated user. // CreatePasskey creates a new app passkey for the authenticated user.
@@ -227,7 +230,11 @@ func (s *AuthService) LoginWithPasskey(ctx context.Context, tokenStr string) (*T
// ListPasskeys returns all app passkeys for a user. // ListPasskeys returns all app passkeys for a user.
func (s *AuthService) ListPasskeys(ctx context.Context, userID string) ([]model.Credential, error) { func (s *AuthService) ListPasskeys(ctx context.Context, userID string) ([]model.Credential, error) {
return s.credentialRepo.FindByUserIDAndType(ctx, userID, "app_passkey") creds, err := s.credentialRepo.FindByUserIDAndType(ctx, userID, "app_passkey")
if err != nil {
return nil, model.NewInternalError("list passkeys", err)
}
return creds, nil
} }
// RevokePasskey deletes an app passkey owned by the user. // RevokePasskey deletes an app passkey owned by the user.
@@ -244,7 +251,10 @@ func (s *AuthService) RevokePasskey(ctx context.Context, userID, credID string)
return model.NewPermissionDeniedError("access denied", model.ErrForbidden) return model.NewPermissionDeniedError("access denied", model.ErrForbidden)
} }
return s.credentialRepo.Delete(ctx, credID) if err := s.credentialRepo.Delete(ctx, credID); err != nil {
return model.NewInternalError("delete credential", err)
}
return nil
} }
// AuthenticateAccessToken validates an access token and returns the active user principal. // AuthenticateAccessToken validates an access token and returns the active user principal.