yesodweb/yesod

Automatic redirect to logout on login

cblp opened this issue · 3 comments

cblp commented

I haven't figured out yet how exactly this happens, but sometimes my website remembers I am on the LogoutR page, and after successful login redirects me to the LogoutR, so I see message You successfully logged in but I'm logged out.

I think, it may be useful to skip LogoutR when trying to save ultimate destination, or when it is read. I can write a pull request, just give me a hint what is the proper solution.

jezen commented

You could do something like this:

instance YesodAuth App where
 
  onLogin = do
    lookupSession "_ULT" >>= \case
      Just url -> case parseRoute (toSegmentsAndQuery (encodeUtf8 url)) of
        Just LogoutR -> clearUltDest
        _ -> pure ()
      Nothing -> pure ()

I'm looking at the yesod-scaffold repo (branch postgres). Wouldn't that patch be a nice one for Foundation.hs?
Another possibility might be to implement redirectToReferer and return False if the destination is the logout route. But I'm not sure if the "referer" only refers to the Referer HTTP Header or also to the destination...

cblp commented

@jezen, it doesn't look like a systematic solution. Yesod already knows what LogoutR is https://github.com/yesodweb/yesod/blob/master/yesod-auth/Yesod/Auth/Routes.hs and defines its behaviour.