diff --git a/yesod-auth/ChangeLog.md b/yesod-auth/ChangeLog.md index 258ff474..fd65b843 100644 --- a/yesod-auth/ChangeLog.md +++ b/yesod-auth/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-auth +## 1.6.7 + +* Redirect behavior of `clearCreds` depends on request type [#1598](https://github.com/yesodweb/yesod/pull/1598) + ## 1.6.6 * Deprecated `Yesod.Auth.GoogleEmail2`, see [#1579](https://github.com/yesodweb/yesod/issues/1579) and [migration blog post](https://pbrisbin.com/posts/googleemail2_deprecation/) diff --git a/yesod-auth/Yesod/Auth.hs b/yesod-auth/Yesod/Auth.hs index 60169f6e..cb66f288 100644 --- a/yesod-auth/Yesod/Auth.hs +++ b/yesod-auth/Yesod/Auth.hs @@ -421,14 +421,20 @@ authLayoutJson w json = selectRep $ do -- -- @since 1.1.7 clearCreds :: (MonadHandler m, YesodAuth (HandlerSite m)) - => Bool -- ^ if HTTP redirect to 'logoutDest' should be done + => Bool -- ^ if HTTP, redirect to 'logoutDest' -> m () clearCreds doRedirects = do - y <- getYesod onLogout deleteSession credsKey - when doRedirects $ do - redirectUltDest $ logoutDest y + y <- getYesod + aj <- acceptsJson + case (aj, doRedirects) of + (True, _) -> sendResponse successfulLogout + (False, True) -> redirectUltDest (logoutDest y) + _ -> return () + where successfulLogout = object ["message" .= msg] + msg :: Text + msg = "Logged out successfully!" getCheckR :: AuthHandler master TypedContent getCheckR = do diff --git a/yesod-auth/yesod-auth.cabal b/yesod-auth/yesod-auth.cabal index 2074b674..12a5a12b 100644 --- a/yesod-auth/yesod-auth.cabal +++ b/yesod-auth/yesod-auth.cabal @@ -1,5 +1,5 @@ name: yesod-auth -version: 1.6.6 +version: 1.6.7 license: MIT license-file: LICENSE author: Michael Snoyman, Patrick Brisbin