The github repo for this code is at here.
tldr; use this instance:
The app we’re using was built by running
snap init and
adding the following code:
src/Application.hs we’ve added the following imports:
and the following definition to our
src/Site.hs we’ve added the following language
and Snaplet Init code:
We've also defined a convenience function
"/postgres" route to only logged in users.
getFromPostgres does the dirty work for us by querying a
table that was created as part of the Snaplet-Auth backend.
It will return a list of all users.
"/postgres" is the url to hit to check to see if it's
, ("/postgres", needsAuth getFromPostgres)
What's really doing the heavy lifting of using the postgres snaplet inside of the auth snaplet's route is this instance:
The important difference from the instance above it is
withTop which can be found
From the docs:
-- | Like 'with' but doesn't impose the requirement that the action -- being run be a descendant of the current snaplet.
Essentially, the auth snaplet doesn't know anything about
the postgres snaplet as we've instantiated it (it doesn't
keep around a reference from the Backend module), so we have
to ask the parent context (using