Hello,
The tough problem that happstack-authenticate faces is that it has to be application agnostic. It doesn't really know much at all about how your application handles routing, how it deals with initializing and cleaning up database connections, etc. So, it all it can do is provide you with the functions you will need to initialize, route, and shutdown the authentication stuff.
routeAuthentication is absolutely necessary -- how else would requests get routed to the authentication library?
The authenticateState is provided in case you do want direct access to it, and so that you can pass it to routeAuthenticate. But you don't really need to carry it around everywhere -- you need only pass it to your routing layer.
You can see there that it passes the routeAuthentication function into a the 'implSite' in the routing monad. But the values are not stored in State or anything.
In the example, everything is done in main :: IO (), because that is pretty much all the application does.
In clckwrks, things are deferred until much later. In fact, the authentication layer in clckwrks is implemented as a clckwrks plugin. So, it does not initialize the authentication until it gets around to initializing the plugins:
- jeremy