Please create a self contained small program so we can see what you are doing precisely. Retracting facts from the session generally works, so there is something specific in what you are doing causing the problem.
So I want to do this: if the session exists, you get a redirect from the index page to /user, and if not - each handler redirects you to the index page. Here is an example.
Thanks. That is getting a bit clearer. The index_controller/1 is definitely wrong. First of all, HTTP handlers must succeed: failing or raising an exception is translated into an HTTP error code.
check_session/1 may fail as http_session_data/1 may fail. If this succeeds though, it will redirect and never reach the remainder of index_controller/1.
Hope this helps getting started. What you really want it probably to protect the logged in part of the server using a single handler that has prefix and authentication(Type) set for the root of the protected area. Now any attempt to get to one of the handlers below will call the authentication hook. You can use one of the basic implementations or add your own to deal with the login as you please.
P.S.
Is it me or the official documentation is written badly? Because I’ve tried to use http_write_passwd_file/2 as the documentation says http_write_passwd_file(+File, +Data:list):
The description of Data is a bit clear. Why there is no information about File? How should I write the path to the file? Is it an absolute or abstract path? I’ve always written imperative code and used official websites for infromation. But now it’s so hard for me to understand this logic.