Skip to content

Commit ceeeb16

Browse files
committed
clearCreds redirect behavior depends on request type.
1 parent 006fa6c commit ceeeb16

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

yesod-auth/ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog for yesod-auth
22

3+
## 1.6.7
4+
5+
* Redirect behavior of `clearCreds` depends on request type [#1598](https://github.com/yesodweb/yesod/pull/1598)
6+
37
## 1.6.6
48

59
* Deprecated `Yesod.Auth.GoogleEmail2`, see [#1579](https://github.com/yesodweb/yesod/issues/1579) and [migration blog post](https://pbrisbin.com/posts/googleemail2_deprecation/)

yesod-auth/Yesod/Auth.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,20 @@ authLayoutJson w json = selectRep $ do
421421
--
422422
-- @since 1.1.7
423423
clearCreds :: (MonadHandler m, YesodAuth (HandlerSite m))
424-
=> Bool -- ^ if HTTP redirect to 'logoutDest' should be done
424+
=> Bool -- ^ if HTTP, redirect to 'logoutDest'
425425
-> m ()
426426
clearCreds doRedirects = do
427-
y <- getYesod
428427
onLogout
429428
deleteSession credsKey
430-
when doRedirects $ do
431-
redirectUltDest $ logoutDest y
429+
y <- getYesod
430+
aj <- acceptsJson
431+
case (aj, doRedirects) of
432+
(True, _) -> sendResponse successfulLogout
433+
(False, True) -> redirectUltDest (logoutDest y)
434+
_ -> return ()
435+
where successfulLogout = object ["message" .= msg]
436+
msg :: Text
437+
msg = "Logged out successfully!"
432438

433439
getCheckR :: AuthHandler master TypedContent
434440
getCheckR = do

yesod-auth/yesod-auth.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: yesod-auth
2-
version: 1.6.6
2+
version: 1.6.7
33
license: MIT
44
license-file: LICENSE
55
author: Michael Snoyman, Patrick Brisbin

0 commit comments

Comments
 (0)