Simplicity

Table of contents

No heading

No headings in the article.

Sometimes the best answer is the simple answer. I know we all know this but according to André Gide, a French author and Nobel Prize winner in literature,

"Everything that needs to be said has already been said. But since no one was listening, everything must be said again."

So, my friends, I'm here to say it again. Last week, I was working on an app and I ran into a case where I wanted users to log in first before taking a course. In the event that they are not already logged in, they should be redirected to the login page. If they log in successfully, I want to redirect them back to the page they were.

I'm sure this is easy peasy for some of you. Please bear with me. So, I thought about different ways to go about this. I even checked stack overflow. Some people recommended creating a custom hook and writing some insane lines of code. Others recommended a library.

At first, I went with the custom hook route. But things got complicated real quick. In case you haven't figured it out, yes, I am a lazy developer. I figured maybe I'll pick up another task.

While working on the other task, it dawned on me that I can simply pass a parameter in my URL that stores the previous route. So let's say I am in the \courses\:id\ route, when I get redirected to the login page, the URL becomes \login\?next=\courses\:id\

How did I think of this? Anyways, you get the point. Keep things simple.

Bye for now,