servant-auth-token-persistent

Persistent backend for servant-auth-token server https://github.com/ncrashed/servant-auth-token#readme

Latest on Hackage:0.6.0.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by NCrashed
Maintained by ncrashed@gmail.com

servant-auth-token-persistent

Storage backend on persistent for servant-auth-token server.

An itegration of the backend is simple:

-- | Special monad for authorisation actions
newtype AuthM a = AuthM { unAuthM :: PersistentBackendT IO a }
  deriving (Functor, Applicative, Monad, MonadIO, MonadError ServantErr, HasStorage, HasAuthConfig)

-- | Execution of authorisation actions that require 'AuthHandler' context
runAuth :: AuthM a -> ServerM a
runAuth m = do
  cfg <- asks envAuthConfig
  pool <- asks envPool
  liftHandler $ ExceptT $ runPersistentBackendT cfg pool $ unAuthM m

Don't forget to add migration to your server startup (if you actually want automatic migrations):

-- | Create new server environment
newServerEnv :: MonadIO m => ServerConfig -> m ServerEnv
newServerEnv cfg = do
  let authConfig = defaultAuthConfig
  pool <- liftIO $ do
    pool <- createPool cfg
    -- run migrations
    flip runSqlPool pool $ runMigration S.migrateAllAuth
    -- create default admin if missing one
    _ <- runPersistentBackendT authConfig pool $ ensureAdmin 17 "admin" "123456" "admin@localhost"
    return pool
  let env = ServerEnv {
        envConfig = cfg
      , envAuthConfig = authConfig
      , envPool = pool
      }
  return env

See a full example in servant-auth-token-example-persistent.

Changes

0.6.0.0

  • Breaking changes in servant-auth-token-0.5.0.0.

0.5.1.1

  • Relax servant and servant-server versions.

0.5.1.0

  • Fix instances of ConvertStorage that causes #12

0.5.0.0

  • MTL instances for PersistentBackendT. Use liftDB instead of removed MonadReader SqlBackend instance.

0.3.2.0

  • Initial factor out from parent package.
comments powered byDisqus