Recently I started an application using NodeJS with ExpressJS framework and decided to use passport for authenticate the users. As many other times I wanted to use flash messages so, when user authentication fails, the application shows a message informing about bad credentials. Nothing new on the horizon until.... OMG !!! I can't see the flash messages !!!
Disclaimer: This is a really stupid history with me as starring.
I like to learn from my errors and because of this I decide to write this post both as a punishment and to ensure I don't forget it again.
I was working implementing a sign up process, where the user writes its credentials and system creates as a new user or returns an error message like "Sorry, but a username with that email exists" or similar.
Before introduce any code, the flow is as follows:
/signuppage via GET method.
Data is sent to
/signup resource via POST method, which is responsible to:
/signuppage (that is, using the GET method) with a flash message related to bad credentials.
Note: A flash message is a variable stored within a session that is only available once, for the next request. That is if we put a flash variable and renders a page, the flash variable is available but if we render the same (or other) page again the flash variable is not present (it is destroyed).
The approximate code for the previous flow is as follows. First, the next code is responsible to receive the post data and register the user:
The authentication is delegated to passport, which is implemented as: