completely rewritten to include improved understanding
The Yesod typeclass contains the function isAuthorized which you can adapt so that different routes are only accessible for different user groups.
The scaffolded site shows examples of how to do that, including making the authorization subsite available to everyone:
isAuthorized (AuthR _) _ = return Authorized
The scaffolded site also helpfully includes a subsite for static content. But: that static subsite does not honor what you do in isAuthorized. You can check that by adding a pattern match like
isAuthorized (StaticR _) _ = error "this error is never reached"
You can still access all static content (including newly created one) and you will never encounter this pattern match.
It does make a bit of sense to give everyone access to content like bootstrap or jquery. Still, the same result could be achieved by honouring isAuthorized and always returning Authorized, the same way it's done with the authorization subsite or the favicon handler.
I personally would like to go one step further with dispatch like
isAuthorized (StaticR (StaticRoute ("public":_) _)) _ = pure Authorized
isAuthorized (StaticR (StaticRoute ("admin" :_) _)) _ = checkIsAdmin
isAuthorized (StaticR (StaticRoute ("cats" :_) _)) False = checkIsAllowedToViewCats
:
It seems the only missing bit is to make the static subsite honour the check or to add a shim that does.
Sadly the subsite is a huge amount of complicated code with template haskell and a lot of magic doing complicated things like embedding files in the executable. The way it's included in the scaffolding has yet more magic. I'm also just learning about subsites and my training to see types as documentation fails in contexts like type families or Q Def. For these reasons I couldn't figure out how to add the check. Any pointers would be appreciated.