Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling maybeAuth and friends in version 1.6 #1488

Closed
paul-rouse opened this issue Feb 19, 2018 · 5 comments
Closed

Calling maybeAuth and friends in version 1.6 #1488

paul-rouse opened this issue Feb 19, 2018 · 5 comments

Comments

@paul-rouse
Copy link
Contributor

Am I being totally thick (entirely possible 馃槃)? What is the intended way to upgrade this sort of code to version 1.6, now that maybeAuth is in AuthHandler?

getHomeR :: Handler Html
getHomeR = do
    mauth <- maybeAuth
    ...

I can write a function that runs it, but it messes with the RunHandlerEnv, which hardly seems right! Have I missed something?

@snoyberg
Copy link
Member

Great catch, this is definitely a bug in the API. I'll push out a fix shortly I hope.

@paul-rouse
Copy link
Contributor Author

I did wonder whether the function I wrote could be made general, but I think it would have to be generated somewhere in the template haskell, since, at least the way I've done it, it bakes in the master route constructor, and therefore the foundation type. Probably not ideal, though.

runAuthHandler :: SubHandlerFor Auth App a -> HandlerFor App a
runAuthHandler (SubHandlerFor f) = HandlerFor $ \hd -> f hd
      { handlerEnv =
          let rhe = handlerEnv hd
          in rhe { rheRoute = case rheRoute rhe of
                                Just (AuthR subR) -> Just subR
                                _                 -> Nothing
                 , rheRouteToMaster = AuthR
                 , rheChild = getAuth (rheSite rhe)
                 }
      }

getHomeR :: Handler Html
getHomeR = do
    mauth <- runAuthHandler maybeAuth

@snoyberg
Copy link
Member

I've pushed a commit which I believe addresses this, a3f1302. Can you give it a shot?

@paul-rouse
Copy link
Contributor Author

Great, yes, that works perfectly in the example I was trying (the test for yesod-auth-hashdb).

Thanks!

@snoyberg
Copy link
Member

Awesome, thanks for confirming. I've just released version 1.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants