This subject is immense; were I to relate everything I know about it, a large volume would be required.
Allah, the Exalted, says:
"As for man, when his Lord tests him and then honors him and showers him with favors, he says, ‘My Lord has honored me.’ But when He tests him and restricts his provision, he says, ‘My Lord has humiliated me.’" (Qur’an 89:15-16)
Allah—blessed and exalted—is He—then declares: "Never! (kallā)."
The word kallā is both a rebuke and an alert: a rebuke against uttering such a claim, and an alert to what Allah is about to state and command. The point is that not everyone who receives worldly blessings is thereby being honored by Allah, nor is everyone whose means are tightened thereby being humiliated. Rather, He tries His servant with both ease and hardship. He may bestow worldly bounty upon someone He does not love and who holds no rank with Him, luring that person on step by step; and He may withhold it from someone He loves and protects, lest the gift diminish that person’s station with Him or lead him into what He dislikes.
[Faith and God-consciousness as the root of prophetic and saintly marvels]
Likewise, the karamāt (divinely granted marvels) of the awliyāʾ must be rooted in faith and piety. Whatever arises from disbelief, rebellion, or disobedience belongs to the extraordinary feats of Allah’s enemies, not to the honors of His friends. Thus, if a person’s wonders are not produced through prayer, Qur’an recitation and remembrance, night vigil, and supplication, but instead appear alongside acts of polytheism—such as calling upon the dead or the absent—or through sin, flagrant disobedience, and the consumption of what is forbidden, like snakes, hornets, beetles, blood, and other such abominations—