yesod-auth-account和requireAuth函数

时间:2014-05-09 06:58:13

标签: haskell yesod

函数requireAuthrequireAuthId会导致编译错误

Couldn't match type `Yesod.Auth.Account.Username'
                  with `KeyBackend
                          persistent-1.3.0.6:Database.Persist.Sql.Types.SqlBackend
                          (KeyEntity Yesod.Auth.Account.Username)'
    In a stmt of a 'do' block: requireAuth

我正在使用yesod-auth-account-1.2.5插件。以下是设置:

instance YesodAuth App where
    type AuthId App = Username
    loginDest _ = HomeR
    logoutDest _ = HomeR
    authPlugins _ = [ accountPlugin ]
    getAuthId = return . Just . credsIdent
    authHttpManager = httpManager -- error "No manager needed"
    onLogin = return ()
    maybeAuthId = lookupSession "_ID"

它有什么用?

我将Username替换为Key Username

Application is no smaller than the instance head
      in the type family application: PersistEntityBackend Username
    (Use -XUndecidableInstances to permit this)

使用{-# LANGUAGE UndecidableInstances #-}

Couldn't match type `Key Username' with `Text'
    Expected type: Creds App -> HandlerT App IO (Maybe (AuthId App))
      Actual type: Creds App -> HandlerT App IO (Maybe Text)
    In the expression: return . Just . credsIdent
In an equation for `getAuthId':
        getAuthId = return . Just . credsIdent

Couldn't match type `Key Username' with `Text'
    Expected type: HandlerT App IO (Maybe (AuthId App))
      Actual type: HandlerT App IO (Maybe Text)
    In the return type of a call of `lookupSession'
    In the expression: lookupSession "_ID"
    In an equation for `maybeAuthId': maybeAuthId = lookupSession "_ID"

需要其他一些替代品

0 个答案:

没有答案
相关问题