DEV Community

Harcourt Hamsa
Harcourt Hamsa

Posted on

Simplicity

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 a app and I ran into a case where I wanted users to login 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 login 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 mad ass code. Others recommended a library.

At first, I went with the custom hook route. But things got complicated real quick. Incase you haven't figured it out, yes, I am a lazy developer. I figured maybe I'll pickup 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.

Bye for now,

Top comments (0)