The purpose of life is God working all things together for good. That doesn't mean that you are exempt from suffering and trials. It does mean that God is working through all of it for your good. And we know that God causes everything to work together for the good of those who love God and are called according to his purpose for them (Romans 8:28, NLT). Those who are called includes you and all believers in the Lord Jesus Christ. It's those who love God.
When something bad happens to you as a child of God, you can always trust God to bring good out of it. That's because God is always good. He is good to all, especially to those who know Him as Father. So, you can praise God even on the bad days, knowing that God will bring good out of it.
When bad things happen to you as a child of God, you should never doubt His goodness. That means you never blame Him for evil, though the forces of evil in this world are real. One day God will completely destroy evil. Until then, God has a purpose to fulfill in you and the lives of all His children. Rest assured, that purpose is good.
In your dark night of the soul, you can believe that the sun still shines, and that it shall break through your darkness with victory. Walking through the darkness can cause you to grow weary, but hope says to you, a new day is coming. Look for the morning star. You shall see a new day, when God's purpose prevails in your life. The purpose of life is God working all things together for good, according to His purpose.