snaplet-hasql-1.0.2: A Hasql snaplet

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.Auth.Backends.Hasql

Description

Adapted from "snaplet-postgresql-simple"'s auth module.

This module allows you to use the auth snaplet with your user database stored in a Hasql database. When you run your application with this snaplet, a config file will be copied into the the snaplets/hasql-auth directory. This file contains all of the configurable options for the snaplet and allows you to change them without recompiling your application.

To use this snaplet in your application enable the session, postgres, and auth snaplets as follows:

data App = App
    { ... -- your own application state here
    , _sess :: Snaplet SessionManager
    , _db   :: Snaplet (Pool s)
    , _auth :: Snaplet (AuthManager App)
    }

Then in your initializer you'll have something like this:

d <- nestSnaplet "db" db $ hasqlInit
a <- nestSnaplet "auth" auth $ initHasqlAuth sess d

A database table snap_auth_users for users is created on initialisation.

Synopsis

Documentation

newtype HasqlAuthManager s Source

Constructors

HasqlAuthManager 

Fields

pool :: Pool s
 

initHasqlAuth Source

Arguments

:: (CxTx s, Show (CxError s), Show (TxError s), CxAuthUser s) 
=> SnapletLens b SessionManager

Lens to the session snaplet

-> Snaplet (Pool s)

The hasql snaplet

-> SnapletInit b (AuthManager b) 

Initializer for the postgres backend to the auth snaplet.

defAuthTable :: Stmt c Source

Default authentication table layout